FetchableSource and QueryableSource protocols

This commit is contained in:
John Estropia
2016-11-15 18:00:39 +09:00
parent 33a5c123aa
commit b230ed6400
21 changed files with 967 additions and 566 deletions

View File

@@ -40,14 +40,7 @@ public extension CSBaseDataTransaction {
@objc
public func fetchExistingObject(_ object: NSManagedObject) -> Any? {
do {
return try self.bridgeToSwift.context.existingObject(with: object.objectID)
}
catch _ {
return nil
}
return self.bridgeToSwift.context.fetchExisting(object)
}
/**
@@ -59,14 +52,7 @@ public extension CSBaseDataTransaction {
@objc
public func fetchExistingObjectWithID(_ objectID: NSManagedObjectID) -> Any? {
do {
return try self.bridgeToSwift.context.existingObject(with: objectID)
}
catch _ {
return nil
}
return self.bridgeToSwift.context.fetchExisting(objectID)
}
/**
@@ -78,7 +64,7 @@ public extension CSBaseDataTransaction {
@objc
public func fetchExistingObjects(_ objects: [NSManagedObject]) -> [Any] {
return objects.flatMap { try? self.bridgeToSwift.context.existingObject(with: $0.objectID) }
return self.bridgeToSwift.context.fetchExisting(objects)
}
/**
@@ -90,7 +76,7 @@ public extension CSBaseDataTransaction {
@objc
public func fetchExistingObjectsWithIDs(_ objectIDs: [NSManagedObjectID]) -> [Any] {
return objectIDs.flatMap { try? self.bridgeToSwift.context.existingObject(with: $0) }
return self.bridgeToSwift.context.fetchExisting(objectIDs)
}
/**

View File

@@ -40,14 +40,7 @@ public extension CSDataStack {
@objc
public func fetchExistingObject(_ object: NSManagedObject) -> Any? {
do {
return try self.bridgeToSwift.mainContext.existingObject(with: object.objectID)
}
catch _ {
return nil
}
return self.bridgeToSwift.mainContext.fetchExisting(object)
}
/**
@@ -59,14 +52,7 @@ public extension CSDataStack {
@objc
public func fetchExistingObjectWithID(_ objectID: NSManagedObjectID) -> Any? {
do {
return try self.bridgeToSwift.mainContext.existingObject(with: objectID)
}
catch _ {
return nil
}
return self.bridgeToSwift.mainContext.fetchExisting(objectID)
}
/**
@@ -78,7 +64,7 @@ public extension CSDataStack {
@objc
public func fetchExistingObjects(_ objects: [NSManagedObject]) -> [Any] {
return objects.flatMap { try? self.bridgeToSwift.mainContext.existingObject(with: $0.objectID) }
return self.bridgeToSwift.mainContext.fetchExisting(objects)
}
/**
@@ -90,7 +76,7 @@ public extension CSDataStack {
@objc
public func fetchExistingObjectsWithIDs(_ objectIDs: [NSManagedObjectID]) -> [Any] {
return objectIDs.flatMap { try? self.bridgeToSwift.mainContext.existingObject(with: $0) }
return self.bridgeToSwift.mainContext.fetchExisting(objectIDs)
}
/**

View File

@@ -35,6 +35,7 @@ public extension CSDataStack {
/**
Utility for creating an `NSFetchedResultsController` from the `CSDataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `CSListMonitor`s abstraction.
- Note: It is the caller's responsibility to call `-performFetch:` on the created `NSFetchedResultsController`.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter sectionBy: a `CSSectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
@@ -60,6 +61,7 @@ public extension CSUnsafeDataTransaction {
/**
Utility for creating an `NSFetchedResultsController` from the `CSUnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `CSListMonitor`s abstraction.
- Note: It is the caller's responsibility to call `-performFetch:` on the created `NSFetchedResultsController`.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter sectionBy: a `CSSectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections