mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-17 23:14:05 +01:00
Merge branch 'master' into corestore2_develop
# Conflicts: # CoreStore.podspec # Sources/Convenience/NSFetchedResultsController+Convenience.swift # Sources/Info.plist
This commit is contained in:
2
Cartfile
2
Cartfile
@@ -1 +1 @@
|
|||||||
github "JohnEstropia/GCDKit" == 1.2.4
|
github "JohnEstropia/GCDKit" == 1.2.5
|
||||||
|
|||||||
@@ -35,23 +35,162 @@ 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.
|
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 dataStack: the `DataStack` to observe objects from
|
||||||
- parameter fetchRequest: the `NSFetchRequest` instance to use with the `NSFetchedResultsController`
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter from: an optional `From` clause indicating the entity type. If not specified, the `fetchRequest` argument's `entity` property should already be set.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
|
||||||
- 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 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.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public static func createForStack<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
|
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
|
||||||
|
|
||||||
return CoreStoreFetchedResultsController(
|
return self.createFromContext(
|
||||||
context: dataStack.mainContext,
|
transaction.context,
|
||||||
fetchRequest: fetchRequest,
|
fetchRequest: CoreStoreFetchRequest(),
|
||||||
from: from,
|
from: from,
|
||||||
sectionBy: sectionBy,
|
sectionBy: nil,
|
||||||
applyFetchClauses: { fetchRequest in
|
fetchClauses: fetchClauses
|
||||||
|
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
|||||||
@nonobjc
|
@nonobjc
|
||||||
internal init<T: NSManagedObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) {
|
internal init<T: NSManagedObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) {
|
||||||
|
|
||||||
|
CoreStore.assert(
|
||||||
|
fetchClauses.filter { $0 is OrderBy }.count > 0,
|
||||||
|
"An \(typeName(NSFetchedResultsController)) requires an OrderBy clause."
|
||||||
|
)
|
||||||
from?.applyToFetchRequest(fetchRequest, context: context, applyAffectedStores: false)
|
from?.applyToFetchRequest(fetchRequest, context: context, applyAffectedStores: false)
|
||||||
applyFetchClauses(fetchRequest: fetchRequest)
|
applyFetchClauses(fetchRequest: fetchRequest)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user