mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-17 23:14:05 +01:00
elegant queries
This commit is contained in:
@@ -266,9 +266,9 @@ public class DataStack: NSObject {
|
||||
Begins a transaction synchronously where NSManagedObject creates, updates, and deletes can be made.
|
||||
|
||||
:param: closure the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent NSManagedObjectContext.
|
||||
:returns: a SaveResult value indicating success or failure.
|
||||
:returns: a SaveResult value indicating success or failure, or nil if the transaction was not comitted synchronously
|
||||
*/
|
||||
public func performTransactionAndWait(closure: (transaction: DataTransaction) -> ()) -> SaveResult {
|
||||
public func performTransactionAndWait(closure: (transaction: DataTransaction) -> ()) -> SaveResult? {
|
||||
|
||||
return DataTransaction(
|
||||
mainContext: self.mainContext,
|
||||
|
||||
@@ -30,7 +30,7 @@ import GCDKit
|
||||
/**
|
||||
The DataTransaction provides an interface for NSManagedObject creates, updates, and deletes. A transaction object should typically be only used from within a transaction block initiated from DataStack.performTransaction(_:), or from HardcoreData.performTransaction(_:).
|
||||
*/
|
||||
public class DataTransaction {
|
||||
public final class DataTransaction {
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
@@ -102,9 +102,9 @@ public class DataTransaction {
|
||||
HardcoreData.assert(!self.isCommitted, "Attempted to commit a DataTransaction more than once.")
|
||||
|
||||
self.isCommitted = true
|
||||
self.context.saveAsynchronouslyWithCompletion { [weak self] (result) -> () in
|
||||
self.context.saveAsynchronouslyWithCompletion { (result) -> () in
|
||||
|
||||
self?.result = result
|
||||
self.result = result
|
||||
completion(result: result)
|
||||
}
|
||||
}
|
||||
@@ -114,15 +114,13 @@ public class DataTransaction {
|
||||
|
||||
:returns: a SaveResult value indicating success or failure.
|
||||
*/
|
||||
public func commitAndWait() -> SaveResult {
|
||||
public func commitAndWait() {
|
||||
|
||||
HardcoreData.assert(self.transactionQueue.isCurrentExecutionContext() == true, "Attempted to commit a DataTransaction outside a transaction queue.")
|
||||
HardcoreData.assert(!self.isCommitted, "Attempted to commit a DataTransaction more than once.")
|
||||
|
||||
self.isCommitted = true
|
||||
let result = self.context.saveSynchronously()
|
||||
self.result = result
|
||||
return result
|
||||
self.result = self.context.saveSynchronously()
|
||||
}
|
||||
|
||||
|
||||
@@ -141,24 +139,16 @@ public class DataTransaction {
|
||||
self.transactionQueue.barrierAsync {
|
||||
|
||||
self.closure(transaction: self)
|
||||
if !self.isCommitted {
|
||||
|
||||
self.commit { (result) -> () in }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal func performAndWait() -> SaveResult {
|
||||
internal func performAndWait() -> SaveResult? {
|
||||
|
||||
self.transactionQueue.barrierSync {
|
||||
|
||||
self.closure(transaction: self)
|
||||
if !self.isCommitted {
|
||||
|
||||
self.commitAndWait()
|
||||
}
|
||||
}
|
||||
return self.result!
|
||||
return self.result
|
||||
}
|
||||
|
||||
|
||||
@@ -174,34 +164,54 @@ public class DataTransaction {
|
||||
|
||||
// MARK: - DataContextProvider
|
||||
|
||||
extension DataTransaction: Queryable {
|
||||
extension DataTransaction: ObjectQueryable {
|
||||
|
||||
public func findFirst<T: NSManagedObject>(entity: T.Type) -> T? {
|
||||
|
||||
return self.context.findFirst(entity)
|
||||
}
|
||||
|
||||
public func findFirst<T: NSManagedObject>(query: Query<T>) -> T? {
|
||||
public func findFirst<T: NSManagedObject>(entity: T.Type, customizeFetch: FetchRequestCustomization?) -> T? {
|
||||
|
||||
return self.context.findFirst(entity, customizeFetch: customizeFetch)
|
||||
}
|
||||
|
||||
public func findFirst<T: NSManagedObject>(query: ObjectQuery<T>) -> T? {
|
||||
|
||||
return self.context.findFirst(query)
|
||||
}
|
||||
|
||||
public func findFirst<T: NSManagedObject>(query: ObjectQuery<T>, customizeFetch: FetchRequestCustomization?) -> T? {
|
||||
|
||||
return self.context.findFirst(query, customizeFetch: customizeFetch)
|
||||
}
|
||||
|
||||
public func findAll<T: NSManagedObject>(entity: T.Type) -> [T]? {
|
||||
|
||||
return self.context.findAll(entity)
|
||||
}
|
||||
|
||||
public func findAll<T: NSManagedObject>(query: Query<T>) -> [T]? {
|
||||
public func findAll<T: NSManagedObject>(entity: T.Type, customizeFetch: FetchRequestCustomization?) -> [T]? {
|
||||
|
||||
return self.context.findAll(entity, customizeFetch: customizeFetch)
|
||||
}
|
||||
|
||||
public func findAll<T: NSManagedObject>(query: ObjectQuery<T>) -> [T]? {
|
||||
|
||||
return self.context.findAll(query)
|
||||
}
|
||||
|
||||
public func findAll<T: NSManagedObject>(query: ObjectQuery<T>, customizeFetch: FetchRequestCustomization?) -> [T]? {
|
||||
|
||||
return self.context.findAll(query, customizeFetch: customizeFetch)
|
||||
}
|
||||
|
||||
public func count<T: NSManagedObject>(entity: T.Type) -> Int {
|
||||
|
||||
return self.context.count(entity)
|
||||
}
|
||||
|
||||
public func count<T: NSManagedObject>(query: Query<T>) -> Int {
|
||||
public func count<T: NSManagedObject>(query: ObjectQuery<T>) -> Int {
|
||||
|
||||
return self.context.count(query)
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@ import GCDKit
|
||||
|
||||
|
||||
/**
|
||||
HardcoreData - Simple, elegant, and smart Core Data management with Swift
|
||||
|
||||
The HardcoreData struct is the main entry point for all other APIs.
|
||||
*/
|
||||
public struct HardcoreData {
|
||||
@@ -75,9 +73,9 @@ public struct HardcoreData {
|
||||
Using the defaultStack, begins a transaction asynchronously where NSManagedObject creates, updates, and deletes can be made.
|
||||
|
||||
:param: closure the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent NSManagedObjectContext.
|
||||
:returns: a SaveResult value indicating success or failure.
|
||||
:returns: a SaveResult value indicating success or failure, or nil if the transaction was not comitted synchronously
|
||||
*/
|
||||
public static func performTransactionAndWait(closure: (transaction: DataTransaction) -> ()) -> SaveResult {
|
||||
public static func performTransactionAndWait(closure: (transaction: DataTransaction) -> ()) -> SaveResult? {
|
||||
|
||||
return self.defaultStack.performTransactionAndWait(closure)
|
||||
}
|
||||
@@ -87,7 +85,7 @@ public struct HardcoreData {
|
||||
|
||||
case Trace
|
||||
case Notice
|
||||
case Alert
|
||||
case Warning
|
||||
case Fatal
|
||||
}
|
||||
|
||||
|
||||
@@ -48,32 +48,37 @@ public extension NSManagedObject {
|
||||
|
||||
// MARK: Querying
|
||||
|
||||
public class func WHERE(predicate: NSPredicate) -> Query<NSManagedObject> {
|
||||
public class func WHERE(predicate: NSPredicate) -> ObjectQuery<NSManagedObject> {
|
||||
|
||||
return Query(entity: self).WHERE(predicate)
|
||||
return ObjectQuery(entity: self).WHERE(predicate)
|
||||
}
|
||||
|
||||
public class func WHERE(value: Bool) -> Query<NSManagedObject> {
|
||||
public class func WHERE(value: Bool) -> ObjectQuery<NSManagedObject> {
|
||||
|
||||
return self.WHERE(NSPredicate(value: value))
|
||||
}
|
||||
|
||||
public class func WHERE(format: String, _ args: CVarArgType...) -> Query<NSManagedObject> {
|
||||
public class func WHERE(format: String, _ args: CVarArgType...) -> ObjectQuery<NSManagedObject> {
|
||||
|
||||
return self.WHERE(NSPredicate(format: format, arguments: withVaList(args, { $0 })))
|
||||
return self.WHERE(NSPredicate(format: format, arguments: getVaList(args)))
|
||||
}
|
||||
|
||||
public class func WHERE(format: String, argumentArray: [AnyObject]?) -> Query<NSManagedObject> {
|
||||
public class func WHERE(format: String, argumentArray: [AnyObject]?) -> ObjectQuery<NSManagedObject> {
|
||||
|
||||
return self.WHERE(NSPredicate(format: format, argumentArray: argumentArray))
|
||||
}
|
||||
|
||||
public class func SORTEDBY(order: [SortOrder]) -> Query<NSManagedObject> {
|
||||
public class func WHERE(attributeName: AttributeName, isEqualTo value: NSObject?) -> ObjectQuery<NSManagedObject> {
|
||||
|
||||
return Query(entity: self).SORTEDBY(order)
|
||||
return ObjectQuery(entity: self).WHERE(attributeName, isEqualTo: value)
|
||||
}
|
||||
|
||||
public class func SORTEDBY(order: SortOrder, _ subOrder: SortOrder...) -> Query<NSManagedObject> {
|
||||
public class func SORTEDBY(order: [SortOrder]) -> ObjectQuery<NSManagedObject> {
|
||||
|
||||
return ObjectQuery(entity: self).SORTEDBY(order)
|
||||
}
|
||||
|
||||
public class func SORTEDBY(order: SortOrder, _ subOrder: SortOrder...) -> ObjectQuery<NSManagedObject> {
|
||||
|
||||
return self.SORTEDBY([order] + subOrder)
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public extension NSManagedObjectContext {
|
||||
self.reset()
|
||||
if let completion = completion {
|
||||
|
||||
GCDBlock.async(.Main) {
|
||||
GCDQueue.Main.async {
|
||||
|
||||
completion(result: SaveResult(hasChanges: false))
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public extension NSManagedObjectContext {
|
||||
|
||||
if let completion = completion {
|
||||
|
||||
GCDBlock.async(.Main) {
|
||||
GCDQueue.Main.async {
|
||||
|
||||
completion(result: SaveResult(hasChanges: true))
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public extension NSManagedObjectContext {
|
||||
"Failed to save NSManagedObjectContext.")
|
||||
if let completion = completion {
|
||||
|
||||
GCDBlock.async(.Main) {
|
||||
GCDQueue.Main.async {
|
||||
|
||||
completion(result: SaveResult(error))
|
||||
}
|
||||
@@ -147,7 +147,7 @@ public extension NSManagedObjectContext {
|
||||
}
|
||||
else if let completion = completion {
|
||||
|
||||
GCDBlock.async(.Main) {
|
||||
GCDQueue.Main.async {
|
||||
|
||||
completion(result: SaveResult(hasChanges: false))
|
||||
}
|
||||
@@ -274,30 +274,40 @@ public extension NSManagedObjectContext {
|
||||
|
||||
// MARK: - DataContextProvider
|
||||
|
||||
extension NSManagedObjectContext: Queryable {
|
||||
extension NSManagedObjectContext: ObjectQueryable {
|
||||
|
||||
public func findFirst<T: NSManagedObject>(entity: T.Type) -> T? {
|
||||
|
||||
return self.findFirst(Query(entity: entity))
|
||||
return self.findFirst(entity, customizeFetch: nil)
|
||||
}
|
||||
|
||||
public func findFirst<T: NSManagedObject>(query: Query<T>) -> T? {
|
||||
public func findFirst<T: NSManagedObject>(entity: T.Type, customizeFetch: FetchRequestCustomization?) -> T? {
|
||||
|
||||
var query = query
|
||||
query.fetchLimit = 1
|
||||
let fetchRequest = query.createFetchRequestInContext(self)
|
||||
return self.findFirst(ObjectQuery(entity: entity), customizeFetch: customizeFetch)
|
||||
}
|
||||
|
||||
public func findFirst<T: NSManagedObject>(query: ObjectQuery<T>) -> T? {
|
||||
|
||||
return self.findFirst(query, customizeFetch: nil)
|
||||
}
|
||||
|
||||
public func findFirst<T: NSManagedObject>(query: ObjectQuery<T>, customizeFetch: FetchRequestCustomization?) -> T? {
|
||||
|
||||
let fetchRequest = query.createFetchRequestForContext(self)
|
||||
customizeFetch?(fetchRequest: fetchRequest)
|
||||
fetchRequest.fetchLimit = 1
|
||||
fetchRequest.resultType = .ManagedObjectResultType
|
||||
|
||||
var fetchResults: [T]?
|
||||
var error: NSError?
|
||||
self.performBlockAndWait {
|
||||
|
||||
var error: NSError?
|
||||
fetchResults = self.executeFetchRequest(fetchRequest, error: &error) as? [T]
|
||||
if fetchResults == nil {
|
||||
|
||||
HardcoreData.handleError(
|
||||
error!,
|
||||
"Failed executing fetch request.")
|
||||
}
|
||||
}
|
||||
if fetchResults == nil {
|
||||
|
||||
HardcoreData.handleError(error!, "Failed executing fetch request.")
|
||||
return nil
|
||||
}
|
||||
|
||||
return fetchResults?.first
|
||||
@@ -305,24 +315,34 @@ extension NSManagedObjectContext: Queryable {
|
||||
|
||||
public func findAll<T: NSManagedObject>(entity: T.Type) -> [T]? {
|
||||
|
||||
return self.findAll(Query(entity: entity))
|
||||
return self.findAll(entity, customizeFetch: nil)
|
||||
}
|
||||
|
||||
public func findAll<T: NSManagedObject>(query: Query<T>) -> [T]? {
|
||||
public func findAll<T: NSManagedObject>(entity: T.Type, customizeFetch: FetchRequestCustomization?) -> [T]? {
|
||||
|
||||
let fetchRequest = query.createFetchRequestInContext(self)
|
||||
return self.findAll(ObjectQuery(entity: entity), customizeFetch: customizeFetch)
|
||||
}
|
||||
|
||||
public func findAll<T: NSManagedObject>(query: ObjectQuery<T>) -> [T]? {
|
||||
|
||||
return self.findAll(query, customizeFetch: nil)
|
||||
}
|
||||
|
||||
public func findAll<T: NSManagedObject>(query: ObjectQuery<T>, customizeFetch: FetchRequestCustomization?) -> [T]? {
|
||||
|
||||
let fetchRequest = query.createFetchRequestForContext(self)
|
||||
fetchRequest.fetchLimit = 0
|
||||
|
||||
var fetchResults: [T]?
|
||||
var error: NSError?
|
||||
self.performBlockAndWait {
|
||||
|
||||
var error: NSError?
|
||||
fetchResults = self.executeFetchRequest(fetchRequest, error: &error) as? [T]
|
||||
if fetchResults == nil {
|
||||
|
||||
HardcoreData.handleError(
|
||||
error!,
|
||||
"Failed executing fetch request.")
|
||||
}
|
||||
}
|
||||
if fetchResults == nil {
|
||||
|
||||
HardcoreData.handleError(error!, "Failed executing fetch request.")
|
||||
return nil
|
||||
}
|
||||
|
||||
return fetchResults
|
||||
@@ -330,12 +350,12 @@ extension NSManagedObjectContext: Queryable {
|
||||
|
||||
public func count<T: NSManagedObject>(entity: T.Type) -> Int {
|
||||
|
||||
return self.count(Query(entity: entity))
|
||||
return self.count(ObjectQuery(entity: entity))
|
||||
}
|
||||
|
||||
public func count<T: NSManagedObject>(query: Query<T>) -> Int {
|
||||
public func count<T: NSManagedObject>(query: ObjectQuery<T>) -> Int {
|
||||
|
||||
let fetchRequest = query.createFetchRequestInContext(self)
|
||||
let fetchRequest = query.createFetchRequestForContext(self)
|
||||
|
||||
var count = 0
|
||||
var error: NSError?
|
||||
@@ -345,9 +365,7 @@ extension NSManagedObjectContext: Queryable {
|
||||
}
|
||||
if count == NSNotFound {
|
||||
|
||||
HardcoreData.handleError(
|
||||
error!,
|
||||
"Failed executing fetch request.")
|
||||
HardcoreData.handleError( error!, "Failed executing fetch request.")
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
internal class NotificationObserver {
|
||||
internal final class NotificationObserver {
|
||||
|
||||
let notificationName: String
|
||||
let object: AnyObject?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Query.swift
|
||||
// ObjectQuery.swift
|
||||
// HardcoreData
|
||||
//
|
||||
// Copyright (c) 2014 John Rommel Estropia
|
||||
@@ -35,39 +35,55 @@ public enum SortOrder {
|
||||
case Descending(AttributeName)
|
||||
}
|
||||
|
||||
public class Query<T: NSManagedObject> {
|
||||
public final class ObjectQuery<T: NSManagedObject> {
|
||||
|
||||
public var fetchLimit: Int = 0
|
||||
public var fetchOffset: Int = 0
|
||||
public var fetchBatchSize: Int = 0
|
||||
|
||||
public var entityName: String {
|
||||
|
||||
return self.entity.entityName
|
||||
}
|
||||
|
||||
public func WHERE(predicate: NSPredicate) -> Query<T> {
|
||||
public func WHERE(predicate: NSPredicate) -> ObjectQuery<T> {
|
||||
|
||||
if self.predicate != nil {
|
||||
|
||||
HardcoreData.log(.Warning, message: "Attempted to set a Query's WHERE clause more than once. The last predicate set will be used.")
|
||||
}
|
||||
self.predicate = predicate
|
||||
return self
|
||||
}
|
||||
|
||||
public func WHERE(value: Bool) -> Query<T> {
|
||||
public func WHERE(value: Bool) -> ObjectQuery<T> {
|
||||
|
||||
return self.WHERE(NSPredicate(value: value))
|
||||
}
|
||||
|
||||
public func WHERE(format: String, _ args: CVarArgType...) -> Query<T> {
|
||||
public func WHERE(format: String, _ args: CVarArgType...) -> ObjectQuery<T> {
|
||||
|
||||
return self.WHERE(NSPredicate(format: format, arguments: withVaList(args, { $0 })))
|
||||
return self.WHERE(NSPredicate(format: format, arguments: getVaList(args)))
|
||||
}
|
||||
|
||||
public func WHERE(format: String, argumentArray: [AnyObject]?) -> Query<T> {
|
||||
public func WHERE(format: String, argumentArray: [AnyObject]?) -> ObjectQuery<T> {
|
||||
|
||||
return self.WHERE(NSPredicate(format: format, argumentArray: argumentArray))
|
||||
}
|
||||
|
||||
public func SORTEDBY(order: [SortOrder]) -> Query<T> {
|
||||
public func WHERE(attributeName: AttributeName, isEqualTo value: NSObject?) -> ObjectQuery<T> {
|
||||
|
||||
return self.WHERE(value == nil
|
||||
? NSPredicate(format: "\(attributeName) == nil")!
|
||||
: NSPredicate(format: "\(attributeName) == %@", value!)!)
|
||||
}
|
||||
|
||||
public func SORTEDBY(order: [SortOrder]) -> ObjectQuery<T> {
|
||||
|
||||
if self.sortDescriptors != nil {
|
||||
|
||||
HardcoreData.log(.Warning, message: "Attempted to set a Query's SORTEDBY clause more than once. The last sort order set will be used.")
|
||||
}
|
||||
self.sortDescriptors = order.map { sortOrder in
|
||||
|
||||
switch sortOrder {
|
||||
@@ -86,25 +102,11 @@ public class Query<T: NSManagedObject> {
|
||||
return self
|
||||
}
|
||||
|
||||
public func SORTEDBY(order: SortOrder, _ subOrder: SortOrder...) -> Query<T> {
|
||||
public func SORTEDBY(order: SortOrder, _ subOrder: SortOrder...) -> ObjectQuery<T> {
|
||||
|
||||
return self.SORTEDBY([order] + subOrder)
|
||||
}
|
||||
|
||||
public func createFetchRequestInContext(context: NSManagedObjectContext) -> NSFetchRequest {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
fetchRequest.entity = NSEntityDescription.entityForName(
|
||||
self.entityName,
|
||||
inManagedObjectContext: context)
|
||||
fetchRequest.fetchLimit = self.fetchLimit
|
||||
fetchRequest.fetchOffset = self.fetchOffset
|
||||
fetchRequest.fetchBatchSize = self.fetchBatchSize
|
||||
fetchRequest.predicate = self.predicate
|
||||
|
||||
return fetchRequest
|
||||
}
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal init(entity: T.Type) {
|
||||
@@ -112,12 +114,21 @@ public class Query<T: NSManagedObject> {
|
||||
self.entity = entity
|
||||
}
|
||||
|
||||
internal func createFetchRequestForContext(context: NSManagedObjectContext) -> NSFetchRequest {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
fetchRequest.entity = NSEntityDescription.entityForName(
|
||||
self.entityName,
|
||||
inManagedObjectContext: context)
|
||||
fetchRequest.predicate = self.predicate
|
||||
fetchRequest.sortDescriptors = self.sortDescriptors
|
||||
|
||||
return fetchRequest
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private
|
||||
private let entity: T.Type
|
||||
public var fetchLimit: Int = 0
|
||||
public var fetchOffset: Int = 0
|
||||
public var fetchBatchSize: Int = 0
|
||||
public var predicate: NSPredicate?
|
||||
public var sortDescriptors: [NSSortDescriptor]?
|
||||
private var predicate: NSPredicate?
|
||||
private var sortDescriptors: [NSSortDescriptor]?
|
||||
}
|
||||
47
HardcoreData/ObjectQueryable.swift
Normal file
47
HardcoreData/ObjectQueryable.swift
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// ObjectQueryable.swift
|
||||
// HardcoreData
|
||||
//
|
||||
// Copyright (c) 2014 John Rommel Estropia
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
public typealias FetchRequestCustomization = (fetchRequest: NSFetchRequest) -> ()
|
||||
|
||||
public protocol ObjectQueryable {
|
||||
|
||||
func findFirst<T: NSManagedObject>(entity: T.Type) -> T?
|
||||
func findFirst<T: NSManagedObject>(entity: T.Type, customizeFetch: FetchRequestCustomization?) -> T?
|
||||
|
||||
func findFirst<T: NSManagedObject>(query: ObjectQuery<T>) -> T?
|
||||
func findFirst<T: NSManagedObject>(query: ObjectQuery<T>, customizeFetch: FetchRequestCustomization?) -> T?
|
||||
|
||||
func findAll<T: NSManagedObject>(entity: T.Type) -> [T]?
|
||||
func findAll<T: NSManagedObject>(entity: T.Type, customizeFetch: FetchRequestCustomization?) -> [T]?
|
||||
|
||||
func findAll<T: NSManagedObject>(query: ObjectQuery<T>) -> [T]?
|
||||
func findAll<T: NSManagedObject>(query: ObjectQuery<T>, customizeFetch: FetchRequestCustomization?) -> [T]?
|
||||
|
||||
func count<T: NSManagedObject>(entity: T.Type) -> Int
|
||||
func count<T: NSManagedObject>(query: ObjectQuery<T>) -> Int
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Queryable.swift
|
||||
// ValueQueryable.swift
|
||||
// HardcoreData
|
||||
//
|
||||
// Copyright (c) 2014 John Rommel Estropia
|
||||
@@ -23,16 +23,16 @@
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Foundation
|
||||
|
||||
public protocol Queryable {
|
||||
public protocol ValueQueryable {
|
||||
|
||||
func findFirst<T: NSManagedObject>(entity: T.Type) -> T?
|
||||
func findFirst<T: NSManagedObject>(query: Query<T>) -> T?
|
||||
func findFirst<T: NSManagedObject>(query: ObjectQuery<T>) -> T?
|
||||
|
||||
func findAll<T: NSManagedObject>(entity: T.Type) -> [T]?
|
||||
func findAll<T: NSManagedObject>(query: Query<T>) -> [T]?
|
||||
func findAll<T: NSManagedObject>(query: ObjectQuery<T>) -> [T]?
|
||||
|
||||
func count<T: NSManagedObject>(entity: T.Type) -> Int
|
||||
func count<T: NSManagedObject>(query: Query<T>) -> Int
|
||||
func count<T: NSManagedObject>(query: ObjectQuery<T>) -> Int
|
||||
}
|
||||
Reference in New Issue
Block a user