resurrect utilities for creating NSFetchedResultsController (fixes #119)

This commit is contained in:
John Estropia
2016-11-11 17:32:13 +09:00
parent 73637321ce
commit 33a5c123aa
7 changed files with 405 additions and 244 deletions

View File

@@ -26,199 +26,189 @@
import Foundation
import CoreData
// TODO: Uncomment
//#if os(iOS) || os(watchOS) || os(tvOS)
//
//// MARK: - NSFetchedResultsController
//
//public extension NSFetchedResultsController {
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter dataStack: the `DataStack` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes a `DataStack`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ dataStack: DataStack, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<NSFetchRequestResult> {
//
// return self.createFromContext(
// dataStack.mainContext,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: sectionBy,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter dataStack: the `DataStack` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes a `DataStack`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ dataStack: DataStack, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
//
// return self.createFromContext(
// dataStack.mainContext,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: sectionBy,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter dataStack: the `DataStack` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes a `DataStack`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ dataStack: DataStack, _ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
//
// return self.createFromContext(
// dataStack.mainContext,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: nil,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter dataStack: the `DataStack` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes a `DataStack`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ dataStack: DataStack, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
//
// return self.createFromContext(
// dataStack.mainContext,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: nil,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter transaction: the `UnsafeDataTransaction` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ transaction: UnsafeDataTransaction, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
//
// return self.createFromContext(
// transaction.context,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: sectionBy,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter transaction: the `UnsafeDataTransaction` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ transaction: UnsafeDataTransaction, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
//
// return self.createFromContext(
// transaction.context,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: sectionBy,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter transaction: the `UnsafeDataTransaction` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
//
// return self.createFromContext(
// transaction.context,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: nil,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter transaction: the `UnsafeDataTransaction` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
//
// return self.createFromContext(
// transaction.context,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: nil,
// fetchClauses: fetchClauses
// )
// }
//
//
// // MARK: Internal
//
// @nonobjc
// internal static func createFromContext<T: NSManagedObject>(_ context: NSManagedObjectContext, fetchRequest: CoreStoreFetchRequest<T>, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController<NSFetchRequestResult> {
//
// let controller = CoreStoreFetchedResultsController(
// context: context,
// fetchRequest: fetchRequest,
// from: from,
// sectionBy: sectionBy,
// applyFetchClauses: { fetchRequest in
//
// fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
//
// CoreStore.assert(
// fetchRequest.sortDescriptors?.isEmpty == false,
// "An \(cs_typeName(NSFetchedResultsController<T>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor."
// )
// }
// )
// return controller.upcast()
// }
//}
//
//#endif
#if os(iOS) || os(watchOS) || os(tvOS)
// MARK: - DataStack
public extension DataStack {
/**
Utility for creating an `NSFetchedResultsController` from the `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `DataStack`
*/
@nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<T> {
return createFRC(
fromContext: self.mainContext,
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `DataStack`
*/
@nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> {
return createFRC(
fromContext: self.mainContext,
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from the `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `DataStack`
*/
@nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<T> {
return createFRC(
fromContext: self.mainContext,
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from the `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `DataStack`
*/
@nonobjc
public func createFetchedResultsController<T: NSManagedObject>(forDataStack dataStack: DataStack, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> {
return createFRC(
fromContext: self.mainContext,
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
}
// MARK: - UnsafeDataTransaction
public extension UnsafeDataTransaction {
/**
Utility for creating an `NSFetchedResultsController` from the `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
*/
@nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<T> {
return createFRC(
fromContext: self.context,
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from the `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
*/
@nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> {
return createFRC(
fromContext: self.context,
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from the `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
*/
@nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<T> {
return createFRC(
fromContext: self.context,
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from the `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
*/
@nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> {
return createFRC(
fromContext: self.context,
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
}
// MARK: - Private
fileprivate func createFRC<T: NSManagedObject>(fromContext context: NSManagedObjectContext, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> {
let controller = CoreStoreFetchedResultsController(
context: context,
fetchRequest: CoreStoreFetchRequest().dynamicCast(),
from: from,
sectionBy: sectionBy,
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest as! NSFetchRequest<NSFetchRequestResult>) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController<NSManagedObject>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor."
)
}
)
return controller.dynamicCast()
}
#endif

View File

@@ -184,9 +184,8 @@ public extension BaseDataTransaction {
/**
Updates existing `ImportableUniqueObject`s or creates them by importing from the specified array of import sources.
Objects are called with `ImportableUniqueObject` methods in the same order as in import sources array.
The array returned from `importUniqueObjects(...)` correctly maps to the order of `sourceArray`.
If `sourceArray` contains multiple import sources with same ID, the last one will be imported.
`ImportableUniqueObject` methods are called on the objects in the same order as they are in the `sourceArray`, and are returned in an array with that same order.
- Warning: If `sourceArray` contains multiple import sources with same ID, no merging will occur and ONLY THE LAST duplicate will be imported.
- parameter into: an `Into` clause specifying the entity type
- parameter sourceArray: the array of objects to import values from
@@ -217,8 +216,7 @@ public extension BaseDataTransaction {
return nil
}
// each subsequent import source with the same ID will replace the existing one
importSourceByID[uniqueIDValue] = source
importSourceByID[uniqueIDValue] = source // effectively replaces duplicate with the latest
return uniqueIDValue
}
}
@@ -227,17 +225,19 @@ public extension BaseDataTransaction {
var existingObjectsByID = Dictionary<T.UniqueIDType, T>()
self.fetchAll(From(entityType), Where(entityType.uniqueIDKeyPath, isMemberOf: sortedIDs))?
.forEach { existingObjectsByID[$0.uniqueIDValue] = $0 }
.forEach { existingObjectsByID[$0.uniqueIDValue] = $0 }
var processedObjectIDs = Set<T.UniqueIDType>()
var result = [T]()
for objectID in sortedIDs {
for objectID in sortedIDs where !processedObjectIDs.contains(objectID) {
guard let source = importSourceByID[objectID] else {
continue
}
try autoreleasepool {
guard let source = importSourceByID[objectID], !processedObjectIDs.contains(objectID) else { return }
if let object = existingObjectsByID[objectID] {
guard entityType.shouldUpdate(from: source, in: self) else { return }
@@ -256,7 +256,6 @@ public extension BaseDataTransaction {
processedObjectIDs.insert(objectID)
}
}
return result
}
}

View File

@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.1</string>
<string>2.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>

View File

@@ -27,40 +27,78 @@ import Foundation
import CoreData
//#if os(iOS) || os(watchOS) || os(tvOS)
//
//// MARK: - NSFetchedResultsController
//
//public extension NSFetchedResultsController {
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `CSDataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `CSListMonitor`s abstractio
//
// - parameter dataStack: the `CSDataStack` to observe objects from
// - parameter fetchRequest: the `NSFetchRequest` instance to use with the `NSFetchedResultsController`
// - parameter from: an optional `CSFrom` clause indicating the entity type. If not specified, the `fetchRequest` argument's `entity` property should already be set.
// - parameter sectionBy: a `CSSectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
// */
// @objc
// public static func cs_createForStack(_ dataStack: CSDataStack, fetchRequest: NSFetchRequest<NSFetchRequestResult>, from: CSFrom?, sectionBy: CSSectionBy?, fetchClauses: [CSFetchClause]) -> NSFetchedResultsController {
//
// return CoreStoreFetchedResultsController(
// context: dataStack.bridgeToSwift.mainContext,
// fetchRequest: fetchRequest,
// from: from?.bridgeToSwift,
// sectionBy: sectionBy?.bridgeToSwift,
// applyFetchClauses: { fetchRequest in
//
// fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
//
// CoreStore.assert(
// fetchRequest.sortDescriptors?.isEmpty == false,
// "An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(CSOrderBy)) clause or any custom \(cs_typeName(CSFetchClause)) that provides a sort descriptor."
// )
// }
// )
// }
//}
//
//#endif
#if os(iOS) || os(watchOS) || os(tvOS)
// MARK: - CSDataStack
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.
- 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.
- parameter fetchClauses: a series of `CSFetchClause` instances for fetching the object list. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: an `NSFetchedResultsController` that observes the `CSDataStack`
*/
@objc
public func createFetchedResultsControllerFrom(_ from: CSFrom, sectionBy: CSSectionBy, fetchClauses: [CSFetchClause]) -> NSFetchedResultsController<NSManagedObject> {
return createFRC(
fromContext: self.bridgeToSwift.mainContext,
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
}
// MARK: - CSUnsafeDataTransaction
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.
- 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
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes an `CSUnsafeDataTransaction`
*/
@objc
public func createFetchedResultsControllerFrom(_ from: CSFrom, sectionBy: CSSectionBy, fetchClauses: [CSFetchClause]) -> NSFetchedResultsController<NSManagedObject> {
return createFRC(
fromContext: self.bridgeToSwift.context,
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
}
// MARK: - Private
fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: CSFrom? = nil, sectionBy: CSSectionBy?, fetchClauses: [CSFetchClause]) -> NSFetchedResultsController<NSManagedObject> {
let controller = CoreStoreFetchedResultsController(
context: context,
fetchRequest: CoreStoreFetchRequest().dynamicCast(),
from: from?.bridgeToSwift.upcast(),
sectionBy: sectionBy?.bridgeToSwift,
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest as! NSFetchRequest<NSFetchRequestResult>) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController<NSManagedObject>.self)) requires a sort information. Specify from a \(cs_typeName(CSOrderBy.self)) clause or any custom \(cs_typeName(CSFetchClause.self)) that provides a sort descriptor."
)
}
)
return controller.dynamicCast()
}
#endif