mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-21 08:59:08 +01:00
Docs update
This commit is contained in:
@@ -30,7 +30,7 @@ import CoreData
|
||||
// MARK: - AsynchronousDataTransaction
|
||||
|
||||
/**
|
||||
The `AsynchronousDataTransaction` provides an interface for `DynamicObject` creates, updates, and deletes. A transaction object should typically be only used from within a transaction block initiated from `DataStack.perform(asynchronous:...)`, or from `CoreStore.perform(synchronous:...)`.
|
||||
The `AsynchronousDataTransaction` provides an interface for `DynamicObject` creates, updates, and deletes. A transaction object should typically be only used from within a transaction block initiated from `DataStack.perform(asynchronous:...)`.
|
||||
*/
|
||||
public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ extension CSCoreStore {
|
||||
@objc
|
||||
public static var modelVersion: String {
|
||||
|
||||
return CoreStore.modelVersion
|
||||
return self.defaultStack.modelVersion
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ extension CSCoreStore {
|
||||
@objc
|
||||
public static func entityTypesByNameForType(_ type: NSManagedObject.Type) -> [EntityName: NSManagedObject.Type] {
|
||||
|
||||
return CoreStore.entityTypesByName(for: type)
|
||||
return self.defaultStack.bridgeToSwift.entityTypesByName(for: type)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ extension CSCoreStore {
|
||||
@objc
|
||||
public static func entityDescriptionForClass(_ type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return CoreStore.entityDescription(for: type)
|
||||
return self.defaultStack.bridgeToSwift.entityDescription(for: type)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,7 +65,7 @@ extension CSCoreStore {
|
||||
|
||||
return bridge {
|
||||
|
||||
CoreStore.beginUnsafe()
|
||||
self.defaultStack.bridgeToSwift.beginUnsafe()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ extension CSCoreStore {
|
||||
|
||||
return bridge {
|
||||
|
||||
CoreStore.beginUnsafe(supportsUndo: supportsUndo)
|
||||
self.defaultStack.bridgeToSwift.beginUnsafe(supportsUndo: supportsUndo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,6 @@ extension CSCoreStore {
|
||||
@objc
|
||||
public static func refreshAndMergeAllObjects() {
|
||||
|
||||
CoreStore.refreshAndMergeAllObjects()
|
||||
self.defaultStack.refreshAndMergeAllObjects()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ public final class CSCoreStore: NSObject {
|
||||
@objc
|
||||
public static var defaultStack: CSDataStack {
|
||||
|
||||
get { return Shared.defaultStack.bridgeToObjectiveC }
|
||||
set { Shared.defaultStack = newValue.bridgeToSwift }
|
||||
get { return CoreStoreDefaults.dataStack.bridgeToObjectiveC }
|
||||
set { CoreStoreDefaults.dataStack = newValue.bridgeToSwift }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ extension Internals {
|
||||
@inline(__always)
|
||||
internal static func log(_ level: LogLevel, message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) {
|
||||
|
||||
Shared.logger.log(
|
||||
CoreStoreDefaults.logger.log(
|
||||
level: level,
|
||||
message: message,
|
||||
fileName: fileName,
|
||||
@@ -47,7 +47,7 @@ extension Internals {
|
||||
@inline(__always)
|
||||
internal static func log(_ error: CoreStoreError, _ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) {
|
||||
|
||||
Shared.logger.log(
|
||||
CoreStoreDefaults.logger.log(
|
||||
error: error,
|
||||
message: message,
|
||||
fileName: fileName,
|
||||
@@ -59,7 +59,7 @@ extension Internals {
|
||||
@inline(__always)
|
||||
internal static func assert( _ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) {
|
||||
|
||||
Shared.logger.assert(
|
||||
CoreStoreDefaults.logger.assert(
|
||||
condition(),
|
||||
message: message(),
|
||||
fileName: fileName,
|
||||
@@ -71,7 +71,7 @@ extension Internals {
|
||||
@inline(__always)
|
||||
internal static func abort(_ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) -> Never {
|
||||
|
||||
Shared.logger.abort(
|
||||
CoreStoreDefaults.logger.abort(
|
||||
message,
|
||||
fileName: fileName,
|
||||
lineNumber: lineNumber,
|
||||
|
||||
@@ -33,9 +33,9 @@ import CoreData
|
||||
extension CoreStore {
|
||||
|
||||
/**
|
||||
Asynchronously adds a `StorageInterface` to the `defaultStack`. Migrations are also initiated by default.
|
||||
Asynchronously adds a `StorageInterface` to the `CoreStoreDefaults.dataStack`. Migrations are also initiated by default.
|
||||
```
|
||||
CoreStore.addStorage(
|
||||
dataStack.addStorage(
|
||||
InMemoryStore(configuration: "Config1"),
|
||||
completion: { result in
|
||||
switch result {
|
||||
@@ -50,13 +50,13 @@ extension CoreStore {
|
||||
*/
|
||||
public static func addStorage<T>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) {
|
||||
|
||||
Shared.defaultStack.addStorage(storage, completion: completion)
|
||||
CoreStoreDefaults.dataStack.addStorage(storage, completion: completion)
|
||||
}
|
||||
|
||||
/**
|
||||
Asynchronously adds a `LocalStorage` to the `defaultStack`. Migrations are also initiated by default.
|
||||
Asynchronously adds a `LocalStorage` to the `CoreStoreDefaults.dataStack`. Migrations are also initiated by default.
|
||||
```
|
||||
let migrationProgress = CoreStore.addStorage(
|
||||
let migrationProgress = dataStack.addStorage(
|
||||
SQLiteStore(fileName: "core_data.sqlite", configuration: "Config1"),
|
||||
completion: { result in
|
||||
switch result {
|
||||
@@ -72,11 +72,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func addStorage<T: LocalStorage>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) -> Progress? {
|
||||
|
||||
return Shared.defaultStack.addStorage(storage, completion: completion)
|
||||
return CoreStoreDefaults.dataStack.addStorage(storage, completion: completion)
|
||||
}
|
||||
|
||||
/**
|
||||
Asynchronously adds a `CloudStorage` to the `defaultStack`. Migrations are also initiated by default.
|
||||
Asynchronously adds a `CloudStorage` to the `CoreStoreDefaults.dataStack`. Migrations are also initiated by default.
|
||||
```
|
||||
guard let storage = ICloudStore(
|
||||
ubiquitousContentName: "MyAppCloudData",
|
||||
@@ -104,11 +104,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func addStorage<T: CloudStorage>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) {
|
||||
|
||||
Shared.defaultStack.addStorage(storage, completion: completion)
|
||||
CoreStoreDefaults.dataStack.addStorage(storage, completion: completion)
|
||||
}
|
||||
|
||||
/**
|
||||
Migrates a local storage to match the `defaultStack`'s managed object model version. This method does NOT add the migrated store to the data stack.
|
||||
Migrates a local storage to match the `CoreStoreDefaults.dataStack`'s managed object model version. This method does NOT add the migrated store to the data stack.
|
||||
|
||||
- parameter storage: the local storage
|
||||
- parameter completion: the closure to be executed on the main queue when the migration completes, either due to success or failure. The closure's `MigrationResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a `.failure` result if an error occurs asynchronously.
|
||||
@@ -117,11 +117,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func upgradeStorageIfNeeded<T: LocalStorage>(_ storage: T, completion: @escaping (MigrationResult) -> Void) throws -> Progress? {
|
||||
|
||||
return try Shared.defaultStack.upgradeStorageIfNeeded(storage, completion: completion)
|
||||
return try CoreStoreDefaults.dataStack.upgradeStorageIfNeeded(storage, completion: completion)
|
||||
}
|
||||
|
||||
/**
|
||||
Checks the migration steps required for the storage to match the `defaultStack`'s managed object model version.
|
||||
Checks the migration steps required for the storage to match the `CoreStoreDefaults.dataStack`'s managed object model version.
|
||||
|
||||
- parameter storage: the local storage
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
@@ -129,6 +129,6 @@ extension CoreStore {
|
||||
*/
|
||||
public static func requiredMigrationsForStorage<T: LocalStorage>(_ storage: T) throws -> [MigrationType] {
|
||||
|
||||
return try Shared.defaultStack.requiredMigrationsForStorage(storage)
|
||||
return try CoreStoreDefaults.dataStack.requiredMigrationsForStorage(storage)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,18 +34,18 @@ import CoreData
|
||||
extension CoreStore {
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, creates an `ObjectMonitor` for the specified `DynamicObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `DynamicObject`.
|
||||
Using the `CoreStoreDefaults.dataStack`, creates an `ObjectMonitor` for the specified `DynamicObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `DynamicObject`.
|
||||
|
||||
- parameter object: the `DynamicObject` to observe changes from
|
||||
- returns: an `ObjectMonitor` that monitors changes to `object`
|
||||
*/
|
||||
public static func monitorObject<O: DynamicObject>(_ object: O) -> ObjectMonitor<O> {
|
||||
|
||||
return Shared.defaultStack.monitorObject(object)
|
||||
return CoreStoreDefaults.dataStack.monitorObject(object)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
|
||||
Using the `CoreStoreDefaults.dataStack`, creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
|
||||
|
||||
- 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.
|
||||
@@ -53,11 +53,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorList<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> ListMonitor<D> {
|
||||
|
||||
return Shared.defaultStack.monitorList(from, fetchClauses)
|
||||
return CoreStoreDefaults.dataStack.monitorList(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
|
||||
Using the `CoreStoreDefaults.dataStack`, creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
|
||||
|
||||
- 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.
|
||||
@@ -65,13 +65,13 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorList<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
|
||||
|
||||
return Shared.defaultStack.monitorList(from, fetchClauses)
|
||||
return CoreStoreDefaults.dataStack.monitorList(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||
```
|
||||
let monitor = CoreStore.monitorList(
|
||||
let monitor = dataStack.monitorList(
|
||||
From<MyPersonEntity>()
|
||||
.where(\.age > 18)
|
||||
.orderBy(.ascending(\.age))
|
||||
@@ -82,11 +82,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorList<B: FetchChainableBuilderType>(_ clauseChain: B) -> ListMonitor<B.ObjectType> {
|
||||
|
||||
return Shared.defaultStack.monitorList(clauseChain.from, clauseChain.fetchClauses)
|
||||
return CoreStoreDefaults.dataStack.monitorList(clauseChain.from, clauseChain.fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
Using the `CoreStoreDefaults.dataStack`, asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
|
||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
@@ -94,11 +94,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ fetchClauses: FetchClause...) {
|
||||
|
||||
Shared.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||
CoreStoreDefaults.dataStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
Using the `CoreStoreDefaults.dataStack`, asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
|
||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
@@ -106,14 +106,14 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ fetchClauses: [FetchClause]) {
|
||||
|
||||
Shared.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||
CoreStoreDefaults.dataStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
|
||||
```
|
||||
CoreStore.monitorList(
|
||||
dataStack.monitorList(
|
||||
createAsynchronously: { (monitor) in
|
||||
self.monitor = monitor
|
||||
},
|
||||
@@ -127,7 +127,7 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorList<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
||||
|
||||
Shared.defaultStack.monitorList(
|
||||
CoreStoreDefaults.dataStack.monitorList(
|
||||
createAsynchronously: createAsynchronously,
|
||||
clauseChain.from,
|
||||
clauseChain.fetchClauses
|
||||
@@ -135,7 +135,7 @@ extension CoreStore {
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
|
||||
Using the `CoreStoreDefaults.dataStack`, creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
|
||||
|
||||
- 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.
|
||||
@@ -144,11 +144,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorSectionedList<D>(_ from: From<D>, _ sectionBy: SectionBy<D>, _ fetchClauses: FetchClause...) -> ListMonitor<D> {
|
||||
|
||||
return Shared.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||
return CoreStoreDefaults.dataStack.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
|
||||
Using the `CoreStoreDefaults.dataStack`, creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
|
||||
|
||||
- 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.
|
||||
@@ -157,13 +157,13 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorSectionedList<D>(_ from: From<D>, _ sectionBy: SectionBy<D>, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
|
||||
|
||||
return Shared.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||
return CoreStoreDefaults.dataStack.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` built from a chain of clauses.
|
||||
```
|
||||
let monitor = CoreStore.monitorSectionedList(
|
||||
let monitor = dataStack.monitorSectionedList(
|
||||
From<MyPersonEntity>()
|
||||
.sectionBy(\.age, { "\($0!) years old" })
|
||||
.where(\.age > 18)
|
||||
@@ -175,7 +175,7 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorSectionedList<B: SectionMonitorBuilderType>(_ clauseChain: B) -> ListMonitor<B.ObjectType> {
|
||||
|
||||
return Shared.defaultStack.monitorSectionedList(
|
||||
return CoreStoreDefaults.dataStack.monitorSectionedList(
|
||||
clauseChain.from,
|
||||
clauseChain.sectionBy,
|
||||
clauseChain.fetchClauses
|
||||
@@ -183,7 +183,7 @@ extension CoreStore {
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
Using the `CoreStoreDefaults.dataStack`, asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
|
||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
@@ -192,11 +192,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorSectionedList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ sectionBy: SectionBy<D>, _ fetchClauses: FetchClause...) {
|
||||
|
||||
Shared.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||
CoreStoreDefaults.dataStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
Using the `CoreStoreDefaults.dataStack`, asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
|
||||
|
||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
@@ -205,13 +205,13 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorSectionedList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ sectionBy: SectionBy<D>, _ fetchClauses: [FetchClause]) {
|
||||
|
||||
Shared.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||
CoreStoreDefaults.dataStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` built from a chain of clauses.
|
||||
```
|
||||
CoreStore.monitorSectionedList(
|
||||
dataStack.monitorSectionedList(
|
||||
createAsynchronously: { (monitor) in
|
||||
self.monitor = monitor
|
||||
},
|
||||
@@ -226,7 +226,7 @@ extension CoreStore {
|
||||
*/
|
||||
public static func monitorSectionedList<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
||||
|
||||
Shared.defaultStack.monitorSectionedList(
|
||||
CoreStoreDefaults.dataStack.monitorSectionedList(
|
||||
createAsynchronously: createAsynchronously,
|
||||
clauseChain.from,
|
||||
clauseChain.sectionBy,
|
||||
|
||||
@@ -33,51 +33,51 @@ import CoreData
|
||||
extension CoreStore {
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the `DynamicObject` instance in the `DataStack`'s context from a reference created from a transaction or from a different managed object context.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the `DynamicObject` instance in the `DataStack`'s context from a reference created from a transaction or from a different managed object context.
|
||||
|
||||
- parameter object: a reference to the object created/fetched outside the `DataStack`
|
||||
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
||||
*/
|
||||
public static func fetchExisting<D: DynamicObject>(_ object: D) -> D? {
|
||||
|
||||
return Shared.defaultStack.fetchExisting(object)
|
||||
return CoreStoreDefaults.dataStack.fetchExisting(object)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the `DynamicObject` instance in the `DataStack`'s context from an `NSManagedObjectID`.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the `DynamicObject` instance in the `DataStack`'s context from an `NSManagedObjectID`.
|
||||
|
||||
- parameter objectID: the `NSManagedObjectID` for the object
|
||||
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
||||
*/
|
||||
public static func fetchExisting<D: DynamicObject>(_ objectID: NSManagedObjectID) -> D? {
|
||||
|
||||
return Shared.defaultStack.fetchExisting(objectID)
|
||||
return CoreStoreDefaults.dataStack.fetchExisting(objectID)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the `DynamicObject` instances in the `DataStack`'s context from references created from a transaction or from a different managed object context.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the `DynamicObject` instances in the `DataStack`'s context from references created from a transaction or from a different managed object context.
|
||||
|
||||
- parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack`
|
||||
- returns: the `DynamicObject` array for objects that exists in the `DataStack`
|
||||
*/
|
||||
public static func fetchExisting<D: DynamicObject, S: Sequence>(_ objects: S) -> [D] where S.Iterator.Element == D {
|
||||
|
||||
return Shared.defaultStack.fetchExisting(objects)
|
||||
return CoreStoreDefaults.dataStack.fetchExisting(objects)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the `DynamicObject` instances in the `DataStack`'s context from a list of `NSManagedObjectID`.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the `DynamicObject` instances in the `DataStack`'s context from a list of `NSManagedObjectID`.
|
||||
|
||||
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
||||
- returns: the `DynamicObject` array for objects that exists in the `DataStack`
|
||||
*/
|
||||
public static func fetchExisting<D: DynamicObject, S: Sequence>(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID {
|
||||
|
||||
return Shared.defaultStack.fetchExisting(objectIDs)
|
||||
return CoreStoreDefaults.dataStack.fetchExisting(objectIDs)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -86,11 +86,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> D? {
|
||||
|
||||
return try Shared.defaultStack.fetchOne(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchOne(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -99,13 +99,13 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> D? {
|
||||
|
||||
return try Shared.defaultStack.fetchOne(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchOne(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||
```
|
||||
let youngestTeen = CoreStore.fetchOne(
|
||||
let youngestTeen = dataStack.fetchOne(
|
||||
From<MyPersonEntity>()
|
||||
.where(\.age > 18)
|
||||
.orderBy(.ascending(\.age))
|
||||
@@ -117,11 +117,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType? {
|
||||
|
||||
return try Shared.defaultStack.fetchOne(clauseChain)
|
||||
return try CoreStoreDefaults.dataStack.fetchOne(clauseChain)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -130,11 +130,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> [D] {
|
||||
|
||||
return try Shared.defaultStack.fetchAll(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchAll(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -143,13 +143,13 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> [D] {
|
||||
|
||||
return try Shared.defaultStack.fetchAll(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchAll(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||
```
|
||||
let people = CoreStore.fetchAll(
|
||||
let people = dataStack.fetchAll(
|
||||
From<MyPersonEntity>()
|
||||
.where(\.age > 18)
|
||||
.orderBy(.ascending(\.age))
|
||||
@@ -161,11 +161,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType] {
|
||||
|
||||
return try Shared.defaultStack.fetchAll(clauseChain)
|
||||
return try CoreStoreDefaults.dataStack.fetchAll(clauseChain)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -174,11 +174,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> Int {
|
||||
|
||||
return try Shared.defaultStack.fetchCount(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchCount(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -187,13 +187,13 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> Int {
|
||||
|
||||
return try Shared.defaultStack.fetchCount(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchCount(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||
```
|
||||
let numberOfAdults = CoreStore.fetchCount(
|
||||
let numberOfAdults = dataStack.fetchCount(
|
||||
From<MyPersonEntity>()
|
||||
.where(\.age > 18)
|
||||
.orderBy(.ascending(\.age))
|
||||
@@ -205,11 +205,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
||||
|
||||
return try Shared.defaultStack.fetchCount(clauseChain)
|
||||
return try CoreStoreDefaults.dataStack.fetchCount(clauseChain)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -218,11 +218,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? {
|
||||
|
||||
return try Shared.defaultStack.fetchObjectID(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -231,13 +231,13 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? {
|
||||
|
||||
return try Shared.defaultStack.fetchObjectID(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||
```
|
||||
let youngestTeenID = CoreStore.fetchObjectID(
|
||||
let youngestTeenID = dataStack.fetchObjectID(
|
||||
From<MyPersonEntity>()
|
||||
.where(\.age > 18)
|
||||
.orderBy(.ascending(\.age))
|
||||
@@ -249,11 +249,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> NSManagedObjectID? {
|
||||
|
||||
return try Shared.defaultStack.fetchObjectID(clauseChain)
|
||||
return try CoreStoreDefaults.dataStack.fetchObjectID(clauseChain)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -262,11 +262,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] {
|
||||
|
||||
return try Shared.defaultStack.fetchObjectIDs(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchObjectIDs(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
|
||||
- parameter from: a `From` clause indicating the entity type
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
@@ -275,7 +275,7 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] {
|
||||
|
||||
return try Shared.defaultStack.fetchObjectIDs(from, fetchClauses)
|
||||
return try CoreStoreDefaults.dataStack.fetchObjectIDs(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,11 +293,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [NSManagedObjectID] {
|
||||
|
||||
return try Shared.defaultStack.fetchObjectIDs(clauseChain)
|
||||
return try CoreStoreDefaults.dataStack.fetchObjectIDs(clauseChain)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
|
||||
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
|
||||
|
||||
@@ -309,11 +309,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: QueryClause...) throws -> U? {
|
||||
|
||||
return try Shared.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||
return try CoreStoreDefaults.dataStack.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
|
||||
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
|
||||
|
||||
@@ -325,7 +325,7 @@ extension CoreStore {
|
||||
*/
|
||||
public static func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: [QueryClause]) throws -> U? {
|
||||
|
||||
return try Shared.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||
return try CoreStoreDefaults.dataStack.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,7 +333,7 @@ extension CoreStore {
|
||||
|
||||
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
|
||||
```
|
||||
let averageAdultAge = CoreStore.queryValue(
|
||||
let averageAdultAge = dataStack.queryValue(
|
||||
From<MyPersonEntity>()
|
||||
.select(Int.self, .average(\.age))
|
||||
.where(\.age > 18)
|
||||
@@ -345,11 +345,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType {
|
||||
|
||||
return try Shared.defaultStack.queryValue(clauseChain)
|
||||
return try CoreStoreDefaults.dataStack.queryValue(clauseChain)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
|
||||
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
|
||||
|
||||
@@ -361,11 +361,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: QueryClause...) throws -> [[String: Any]] {
|
||||
|
||||
return try Shared.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
||||
return try CoreStoreDefaults.dataStack.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
Using the `CoreStoreDefaults.dataStack`, queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
|
||||
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
|
||||
|
||||
@@ -377,7 +377,7 @@ extension CoreStore {
|
||||
*/
|
||||
public static func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: [QueryClause]) throws -> [[String: Any]] {
|
||||
|
||||
return try Shared.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
||||
return try CoreStoreDefaults.dataStack.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,7 +385,7 @@ extension CoreStore {
|
||||
|
||||
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
|
||||
```
|
||||
let results = CoreStore.queryAttributes(
|
||||
let results = dataStack.queryAttributes(
|
||||
From<MyPersonEntity>()
|
||||
.select(
|
||||
NSDictionary.self,
|
||||
@@ -406,6 +406,6 @@ extension CoreStore {
|
||||
*/
|
||||
public static func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary {
|
||||
|
||||
return try Shared.defaultStack.queryAttributes(clauseChain)
|
||||
return try CoreStoreDefaults.dataStack.queryAttributes(clauseChain)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,90 +33,90 @@ import CoreData
|
||||
extension CoreStore {
|
||||
|
||||
/**
|
||||
Returns the `defaultStack`'s model version. The version string is the same as the name of a version-specific .xcdatamodeld file or `CoreStoreSchema`.
|
||||
Returns the `CoreStoreDefaults.dataStack`'s model version. The version string is the same as the name of a version-specific .xcdatamodeld file or `CoreStoreSchema`.
|
||||
*/
|
||||
public static var modelVersion: String {
|
||||
|
||||
return Shared.defaultStack.modelVersion
|
||||
return CoreStoreDefaults.dataStack.modelVersion
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the entity name-to-class type mapping from the `defaultStack`'s model.
|
||||
Returns the entity name-to-class type mapping from the `CoreStoreDefaults.dataStack`'s model.
|
||||
*/
|
||||
public static func entityTypesByName(for type: NSManagedObject.Type) -> [EntityName: NSManagedObject.Type] {
|
||||
|
||||
return Shared.defaultStack.entityTypesByName(for: type)
|
||||
return CoreStoreDefaults.dataStack.entityTypesByName(for: type)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the entity name-to-class type mapping from the `defaultStack`'s model.
|
||||
Returns the entity name-to-class type mapping from the `CoreStoreDefaults.dataStack`'s model.
|
||||
*/
|
||||
public static func entityTypesByName(for type: CoreStoreObject.Type) -> [EntityName: CoreStoreObject.Type] {
|
||||
|
||||
return Shared.defaultStack.entityTypesByName(for: type)
|
||||
return CoreStoreDefaults.dataStack.entityTypesByName(for: type)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass from `defaultStack`'s model.
|
||||
Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass from `CoreStoreDefaults.dataStack`'s model.
|
||||
*/
|
||||
public static func entityDescription(for type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return Shared.defaultStack.entityDescription(for: type)
|
||||
return CoreStoreDefaults.dataStack.entityDescription(for: type)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the `NSEntityDescription` for the specified `CoreStoreObject` subclass from `defaultStack`'s model.
|
||||
Returns the `NSEntityDescription` for the specified `CoreStoreObject` subclass from `CoreStoreDefaults.dataStack`'s model.
|
||||
*/
|
||||
public static func entityDescription(for type: CoreStoreObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return Shared.defaultStack.entityDescription(for: type)
|
||||
return CoreStoreDefaults.dataStack.entityDescription(for: type)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates an `SQLiteStore` with default parameters and adds it to the `defaultStack`. This method blocks until completion.
|
||||
Creates an `SQLiteStore` with default parameters and adds it to the `CoreStoreDefaults.dataStack`. This method blocks until completion.
|
||||
```
|
||||
try CoreStore.addStorageAndWait()
|
||||
```
|
||||
- returns: the local SQLite storage added to the `defaultStack`
|
||||
- returns: the local SQLite storage added to the `CoreStoreDefaults.dataStack`
|
||||
*/
|
||||
@discardableResult
|
||||
public static func addStorageAndWait() throws -> SQLiteStore {
|
||||
|
||||
return try Shared.defaultStack.addStorageAndWait(SQLiteStore())
|
||||
return try CoreStoreDefaults.dataStack.addStorageAndWait(SQLiteStore())
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a `StorageInterface` to the `defaultStack` and blocks until completion.
|
||||
Adds a `StorageInterface` to the `CoreStoreDefaults.dataStack` and blocks until completion.
|
||||
```
|
||||
try CoreStore.addStorageAndWait(InMemoryStore(configuration: "Config1"))
|
||||
```
|
||||
- parameter storage: the `StorageInterface`
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the `StorageInterface` added to the `defaultStack`
|
||||
- returns: the `StorageInterface` added to the `CoreStoreDefaults.dataStack`
|
||||
*/
|
||||
@discardableResult
|
||||
public static func addStorageAndWait<T: StorageInterface>(_ storage: T) throws -> T {
|
||||
|
||||
return try Shared.defaultStack.addStorageAndWait(storage)
|
||||
return try CoreStoreDefaults.dataStack.addStorageAndWait(storage)
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a `LocalStorage` to the `defaultStack` and blocks until completion.
|
||||
Adds a `LocalStorage` to the `CoreStoreDefaults.dataStack` and blocks until completion.
|
||||
```
|
||||
try CoreStore.addStorageAndWait(SQLiteStore(configuration: "Config1"))
|
||||
```
|
||||
- parameter storage: the local storage
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the local storage added to the `defaultStack`. Note that this may not always be the same instance as the parameter argument if a previous `LocalStorage` was already added at the same URL and with the same configuration.
|
||||
- returns: the local storage added to the `CoreStoreDefaults.dataStack`. Note that this may not always be the same instance as the parameter argument if a previous `LocalStorage` was already added at the same URL and with the same configuration.
|
||||
*/
|
||||
@discardableResult
|
||||
public static func addStorageAndWait<T: LocalStorage>(_ storage: T) throws -> T {
|
||||
|
||||
return try Shared.defaultStack.addStorageAndWait(storage)
|
||||
return try CoreStoreDefaults.dataStack.addStorageAndWait(storage)
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a `CloudStorage` to the `defaultStack` and blocks until completion.
|
||||
Adds a `CloudStorage` to the `CoreStoreDefaults.dataStack` and blocks until completion.
|
||||
```
|
||||
guard let storage = ICloudStore(
|
||||
ubiquitousContentName: "MyAppCloudData",
|
||||
@@ -138,6 +138,6 @@ extension CoreStore {
|
||||
@discardableResult
|
||||
public static func addStorageAndWait<T: CloudStorage>(_ storage: T) throws -> T {
|
||||
|
||||
return try Shared.defaultStack.addStorageAndWait(storage)
|
||||
return try CoreStoreDefaults.dataStack.addStorageAndWait(storage)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,18 +32,18 @@ import Foundation
|
||||
extension CoreStore {
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, performs a transaction asynchronously where `NSManagedObject` or `CoreStoreObject` creates, updates, and deletes can be made. The changes are commited automatically after the `task` closure returns. On success, the value returned from closure will be the wrapped as `.success(T)` in the `completion`'s `Result<T>`. Any errors thrown from inside the `task` will be reported as `.failure(CoreStoreError)`. To cancel/rollback changes, call `try transaction.cancel()`, which throws a `CoreStoreError.userCancelled`.
|
||||
Using the `CoreStoreDefaults.dataStack`, performs a transaction asynchronously where `NSManagedObject` or `CoreStoreObject` creates, updates, and deletes can be made. The changes are commited automatically after the `task` closure returns. On success, the value returned from closure will be the wrapped as `.success(T)` in the `completion`'s `Result<T>`. Any errors thrown from inside the `task` will be reported as `.failure(CoreStoreError)`. To cancel/rollback changes, call `try transaction.cancel()`, which throws a `CoreStoreError.userCancelled`.
|
||||
|
||||
- parameter task: the asynchronous closure 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`.
|
||||
- parameter completion: the closure executed after the save completes. The `Result` argument of the closure will either wrap the return value of `task`, or any uncaught errors thrown from within `task`. Cancelled `task`s will be indicated by `.failure(error: CoreStoreError.userCancelled)`. Custom errors thrown by the user will be wrapped in `CoreStoreError.userError(error: Error)`.
|
||||
*/
|
||||
public static func perform<T>(asynchronous task: @escaping (_ transaction: AsynchronousDataTransaction) throws -> T, completion: @escaping (AsynchronousDataTransaction.Result<T>) -> Void) {
|
||||
|
||||
Shared.defaultStack.perform(asynchronous: task, completion: completion)
|
||||
CoreStoreDefaults.dataStack.perform(asynchronous: task, completion: completion)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, performs a transaction asynchronously where `NSManagedObject` or `CoreStoreObject` creates, updates, and deletes can be made. The changes are commited automatically after the `task` closure returns. On success, the value returned from closure will be the argument of the `success` closure. Any errors thrown from inside the `task` will be wrapped in a `CoreStoreError` and reported in the `failure` closure. To cancel/rollback changes, call `try transaction.cancel()`, which throws a `CoreStoreError.userCancelled`.
|
||||
Using the `CoreStoreDefaults.dataStack`, performs a transaction asynchronously where `NSManagedObject` or `CoreStoreObject` creates, updates, and deletes can be made. The changes are commited automatically after the `task` closure returns. On success, the value returned from closure will be the argument of the `success` closure. Any errors thrown from inside the `task` will be wrapped in a `CoreStoreError` and reported in the `failure` closure. To cancel/rollback changes, call `try transaction.cancel()`, which throws a `CoreStoreError.userCancelled`.
|
||||
|
||||
- parameter task: the asynchronous closure 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`.
|
||||
- parameter success: the closure executed after the save succeeds. The `T` argument of the closure will be the value returned from `task`.
|
||||
@@ -51,11 +51,11 @@ extension CoreStore {
|
||||
*/
|
||||
public static func perform<T>(asynchronous task: @escaping (_ transaction: AsynchronousDataTransaction) throws -> T, success: @escaping (T) -> Void, failure: @escaping (CoreStoreError) -> Void) {
|
||||
|
||||
Shared.defaultStack.perform(asynchronous: task, success: success, failure: failure)
|
||||
CoreStoreDefaults.dataStack.perform(asynchronous: task, success: success, failure: failure)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, performs a transaction synchronously where `NSManagedObject` or `CoreStoreObject` creates, updates, and deletes can be made. The changes are commited automatically after the `task` closure returns. On success, the value returned from closure will be the return value of `perform(synchronous:)`. Any errors thrown from inside the `task` will be thrown from `perform(synchronous:)`. To cancel/rollback changes, call `try transaction.cancel()`, which throws a `CoreStoreError.userCancelled`.
|
||||
Using the `CoreStoreDefaults.dataStack`, performs a transaction synchronously where `NSManagedObject` or `CoreStoreObject` creates, updates, and deletes can be made. The changes are commited automatically after the `task` closure returns. On success, the value returned from closure will be the return value of `perform(synchronous:)`. Any errors thrown from inside the `task` will be thrown from `perform(synchronous:)`. To cancel/rollback changes, call `try transaction.cancel()`, which throws a `CoreStoreError.userCancelled`.
|
||||
|
||||
- parameter task: the synchronous non-escaping closure 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`.
|
||||
- parameter waitForAllObservers: When `true`, this method waits for all observers to be notified of the changes before returning. This results in more predictable data update order, but may risk triggering deadlocks. When `false`, this method does not wait for observers to be notified of the changes before returning. This results in lower risk for deadlocks, but the updated data may not have been propagated to the `DataStack` after returning. Defaults to `true`.
|
||||
@@ -64,25 +64,25 @@ extension CoreStore {
|
||||
*/
|
||||
public static func perform<T>(synchronous task: ((_ transaction: SynchronousDataTransaction) throws -> T), waitForAllObservers: Bool = true) throws -> T {
|
||||
|
||||
return try Shared.defaultStack.perform(synchronous: task, waitForAllObservers: waitForAllObservers)
|
||||
return try CoreStoreDefaults.dataStack.perform(synchronous: task, waitForAllObservers: waitForAllObservers)
|
||||
}
|
||||
|
||||
/**
|
||||
Using the `defaultStack`, begins a non-contiguous transaction where `NSManagedObject` or `CoreStoreObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms.
|
||||
Using the `CoreStoreDefaults.dataStack`, begins a non-contiguous transaction where `NSManagedObject` or `CoreStoreObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms.
|
||||
|
||||
- prameter supportsUndo: `undo()`, `redo()`, and `rollback()` methods are only available when this parameter is `true`, otherwise those method will raise an exception. Defaults to `false`. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
|
||||
- returns: a `UnsafeDataTransaction` instance where creates, updates, and deletes can be made.
|
||||
*/
|
||||
public static func beginUnsafe(supportsUndo: Bool = false) -> UnsafeDataTransaction {
|
||||
|
||||
return Shared.defaultStack.beginUnsafe(supportsUndo: supportsUndo)
|
||||
return CoreStoreDefaults.dataStack.beginUnsafe(supportsUndo: supportsUndo)
|
||||
}
|
||||
|
||||
/**
|
||||
Refreshes all registered objects `NSManagedObject`s or `CoreStoreObject`s in the `defaultStack`.
|
||||
Refreshes all registered objects `NSManagedObject`s or `CoreStoreObject`s in the `CoreStoreDefaults.dataStack`.
|
||||
*/
|
||||
public static func refreshAndMergeAllObjects() {
|
||||
|
||||
Shared.defaultStack.refreshAndMergeAllObjects()
|
||||
CoreStoreDefaults.dataStack.refreshAndMergeAllObjects()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,17 +34,17 @@ import CoreData
|
||||
@available(*, deprecated, message: "Call methods directly from the DataStack instead")
|
||||
public enum CoreStore {
|
||||
|
||||
@available(*, unavailable, renamed: "Shared.logger")
|
||||
@available(*, unavailable, renamed: "CoreStoreDefaults.logger")
|
||||
public static var logger: CoreStoreLogger {
|
||||
|
||||
get { return Shared.logger }
|
||||
set { Shared.logger = newValue }
|
||||
get { return CoreStoreDefaults.logger }
|
||||
set { CoreStoreDefaults.logger = newValue }
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "Shared.defaultStack")
|
||||
@available(*, unavailable, renamed: "CoreStoreDefaults.dataStack")
|
||||
public static var defaultStack: DataStack {
|
||||
|
||||
get { return Shared.defaultStack }
|
||||
set { Shared.defaultStack = newValue }
|
||||
get { return CoreStoreDefaults.dataStack }
|
||||
set { CoreStoreDefaults.dataStack = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Shared.swift
|
||||
// CoreStoreDefaults.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2018 John Rommel Estropia
|
||||
@@ -26,19 +26,25 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
// MARK: - Shared
|
||||
// MARK: - CoreStoreDefaults
|
||||
|
||||
/**
|
||||
Global utilities
|
||||
*/
|
||||
public enum Shared {
|
||||
public enum CoreStoreDefaults {
|
||||
|
||||
/**
|
||||
The `CoreStoreLogger` instance to be used. The default logger is an instance of a `DefaultLogger`.
|
||||
*/
|
||||
public static var logger: CoreStoreLogger = DefaultLogger()
|
||||
|
||||
public static var defaultStack: DataStack {
|
||||
|
||||
/**
|
||||
The default `DataStack` instance to be used. If `defaultStack` is not set during the first time accessed, a default-configured `DataStack` will be created.
|
||||
- SeeAlso: `DataStack`
|
||||
- Note: Changing `dataStack` is thread safe, but it is recommended to setup `DataStacks` on a common queue (e.g. the main queue).
|
||||
- Important: If `dataStack` is not set during the first time accessed, a default-configured `DataStack` will be created.
|
||||
*/
|
||||
public static var dataStack: DataStack {
|
||||
|
||||
get {
|
||||
|
||||
@@ -43,7 +43,7 @@ public enum LogLevel {
|
||||
// MARK: - CoreStoreLogger
|
||||
|
||||
/**
|
||||
Custom loggers should implement the `CoreStoreLogger` protocol and pass its instance to `CoreStore.logger`. Calls to `log(...)`, `assert(...)`, and `abort(...)` are not tied to a specific queue/thread, so it is the implementer's job to handle thread-safety.
|
||||
Custom loggers should implement the `CoreStoreLogger` protocol and pass its instance to `CoreStoreDefaults.logger`. Calls to `log(...)`, `assert(...)`, and `abort(...)` are not tied to a specific queue/thread, so it is the implementer's job to handle thread-safety.
|
||||
*/
|
||||
public protocol CoreStoreLogger {
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ extension ValueContainer.Required {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.nickname == "John" }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname == "John" }))
|
||||
```
|
||||
*/
|
||||
public static func == (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
@@ -44,7 +44,7 @@ extension ValueContainer.Required {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.nickname != "John" }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname != "John" }))
|
||||
```
|
||||
*/
|
||||
public static func != (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
@@ -55,7 +55,7 @@ extension ValueContainer.Required {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age < 20 }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age < 20 }))
|
||||
```
|
||||
*/
|
||||
public static func < (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
@@ -66,7 +66,7 @@ extension ValueContainer.Required {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age > 20 }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age > 20 }))
|
||||
```
|
||||
*/
|
||||
public static func > (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
@@ -77,7 +77,7 @@ extension ValueContainer.Required {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age <= 20 }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age <= 20 }))
|
||||
```
|
||||
*/
|
||||
public static func <= (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
@@ -88,7 +88,7 @@ extension ValueContainer.Required {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age >= 20 }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age >= 20 }))
|
||||
```
|
||||
*/
|
||||
public static func >= (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
@@ -99,7 +99,7 @@ extension ValueContainer.Required {
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains the value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ ["Pluto", "Snoopy", "Scooby"] ~= $0.nickname }))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where({ ["Pluto", "Snoopy", "Scooby"] ~= $0.nickname }))
|
||||
```
|
||||
*/
|
||||
public static func ~= <S: Sequence>(_ sequence: S, _ attribute: ValueContainer<O>.Required<V>) -> Where<O> where S.Iterator.Element == V {
|
||||
@@ -116,7 +116,7 @@ extension ValueContainer.Optional {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.nickname == "John" }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname == "John" }))
|
||||
```
|
||||
*/
|
||||
public static func == (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
@@ -127,7 +127,7 @@ extension ValueContainer.Optional {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.nickname != "John" }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname != "John" }))
|
||||
```
|
||||
*/
|
||||
public static func != (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
@@ -138,7 +138,7 @@ extension ValueContainer.Optional {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age < 20 }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age < 20 }))
|
||||
```
|
||||
*/
|
||||
public static func < (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
@@ -156,7 +156,7 @@ extension ValueContainer.Optional {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age > 20 }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age > 20 }))
|
||||
```
|
||||
*/
|
||||
public static func > (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
@@ -174,7 +174,7 @@ extension ValueContainer.Optional {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age <= 20 }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age <= 20 }))
|
||||
```
|
||||
*/
|
||||
public static func <= (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
@@ -192,7 +192,7 @@ extension ValueContainer.Optional {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age >= 20 }))
|
||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age >= 20 }))
|
||||
```
|
||||
*/
|
||||
public static func >= (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
@@ -210,7 +210,7 @@ extension ValueContainer.Optional {
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains the value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ ["Pluto", "Snoopy", "Scooby"] ~= $0.nickname }))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where({ ["Pluto", "Snoopy", "Scooby"] ~= $0.nickname }))
|
||||
```
|
||||
*/
|
||||
public static func ~= <S: Sequence>(_ sequence: S, _ attribute: ValueContainer<O>.Optional<V>) -> Where<O> where S.Iterator.Element == V {
|
||||
@@ -227,7 +227,7 @@ extension RelationshipContainer.ToOne {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ $0.master == me }))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where({ $0.master == me }))
|
||||
```
|
||||
*/
|
||||
public static func == (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where<O> {
|
||||
@@ -238,7 +238,7 @@ extension RelationshipContainer.ToOne {
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ $0.master != me }))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where({ $0.master != me }))
|
||||
```
|
||||
*/
|
||||
public static func != (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where<O> {
|
||||
@@ -249,7 +249,7 @@ extension RelationshipContainer.ToOne {
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains the value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ [john, joe, bob] ~= $0.master }))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where({ [john, joe, bob] ~= $0.master }))
|
||||
```
|
||||
*/
|
||||
public static func ~= <S: Sequence>(_ sequence: S, _ relationship: RelationshipContainer<O>.ToOne<D>) -> Where<O> where S.Iterator.Element == D {
|
||||
|
||||
@@ -45,7 +45,7 @@ import Foundation
|
||||
```
|
||||
`CoreStoreObject` entities for a model version should be added to `CoreStoreSchema` instance.
|
||||
```
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
CoreStoreSchema(
|
||||
modelVersion: "V1",
|
||||
entities: [
|
||||
|
||||
@@ -43,7 +43,7 @@ import Foundation
|
||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||
}
|
||||
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
CoreStoreSchema(
|
||||
modelVersion: "V1",
|
||||
entities: [
|
||||
@@ -76,7 +76,7 @@ public final class CoreStoreSchema: DynamicSchema {
|
||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||
}
|
||||
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
CoreStoreSchema(
|
||||
modelVersion: "V1",
|
||||
entities: [
|
||||
@@ -120,7 +120,7 @@ public final class CoreStoreSchema: DynamicSchema {
|
||||
let name = Value.Required<String>("name", initial: "")
|
||||
}
|
||||
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
CoreStoreSchema(
|
||||
modelVersion: "V1",
|
||||
entityConfigurations: [
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class DataStack: Equatable {
|
||||
/**
|
||||
Convenience initializer for `DataStack` that creates a `SchemaHistory` from a list of `DynamicSchema` versions.
|
||||
```
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
XcodeDataModelSchema(modelName: "MyModelV1"),
|
||||
CoreStoreSchema(
|
||||
modelVersion: "MyModelV2",
|
||||
@@ -92,7 +92,7 @@ public final class DataStack: Equatable {
|
||||
/**
|
||||
Initializes a `DataStack` from a `SchemaHistory` instance.
|
||||
```
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
schemaHistory: SchemaHistory(
|
||||
XcodeDataModelSchema(modelName: "MyModelV1"),
|
||||
CoreStoreSchema(
|
||||
@@ -472,7 +472,7 @@ public final class DataStack: Equatable {
|
||||
enum Static {
|
||||
static var myDataKey: Void?
|
||||
}
|
||||
CoreStore.defaultStack.userInfo[&Static.myDataKey] = myObject
|
||||
CoreStoreDefaults.dataStack.userInfo[&Static.myDataKey] = myObject
|
||||
```
|
||||
- Important: Do not use this method to store thread-sensitive data.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// DiffableDataSource.CollectionView.swift
|
||||
// DiffableDataSource.CollectionView-UIKit.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2018 John Rommel Estropia
|
||||
@@ -23,7 +23,7 @@
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && (os(iOS) || os(tvOS))
|
||||
|
||||
import UIKit
|
||||
import CoreData
|
||||
@@ -41,7 +41,7 @@ extension DiffableDataSource {
|
||||
```
|
||||
self.dataSource = DiffableDataSource.CollectionView<Person>(
|
||||
collectionView: self.collectionView,
|
||||
dataStack: Shared.defaultStack,
|
||||
dataStack: CoreStoreDefaults.dataStack,
|
||||
cellProvider: { (collectionView, indexPath, person) in
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PersonCell") as! PersonCell
|
||||
cell.setPerson(person)
|
||||
@@ -74,7 +74,7 @@ extension DiffableDataSource {
|
||||
```
|
||||
self.dataSource = DiffableDataSource.CollectionView<Person>(
|
||||
collectionView: self.collectionView,
|
||||
dataStack: Shared.defaultStack,
|
||||
dataStack: CoreStoreDefaults.dataStack,
|
||||
cellProvider: { (collectionView, indexPath, person) in
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PersonCell") as! PersonCell
|
||||
cell.setPerson(person)
|
||||
@@ -94,32 +94,10 @@ extension DiffableDataSource {
|
||||
self.cellProvider = cellProvider
|
||||
self.supplementaryViewProvider = supplementaryViewProvider
|
||||
self.dataStack = dataStack
|
||||
self.dispatcher = Internals.DiffableDataUIDispatcher<O>(dataStack: dataStack)
|
||||
|
||||
super.init()
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// self.rawDataSource = UITableViewDiffableDataSource<String, O.ObjectID>(
|
||||
// tableView: tableView,
|
||||
// cellProvider: { [weak self] (tableView, indexPath, objectID) -> UITableViewCell? in
|
||||
//
|
||||
// guard let self = self else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// guard let object = self.dataStack.fetchExisting(objectID) as O? else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return self.cellProvider(tableView, indexPath, object)
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
// else {
|
||||
|
||||
self.rawDataSource = Internals.DiffableDataUIDispatcher<O>(dataStack: dataStack)
|
||||
// }
|
||||
|
||||
collectionView.dataSource = self
|
||||
}
|
||||
|
||||
@@ -140,29 +118,18 @@ extension DiffableDataSource {
|
||||
public func apply(_ snapshot: ListSnapshot<O>, animatingDifferences: Bool = true) {
|
||||
|
||||
let diffableSnapshot = snapshot.diffableSnapshot
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// self.modernDataSource.apply(
|
||||
// diffableSnapshot as! NSDiffableDataSourceSnapshot<String, NSManagedObjectID>,
|
||||
// animatingDifferences: animatingDifferences,
|
||||
// completion: nil
|
||||
// )
|
||||
// }
|
||||
// else {
|
||||
self.dispatcher.apply(
|
||||
diffableSnapshot as! Internals.DiffableDataSourceSnapshot,
|
||||
view: self.collectionView,
|
||||
animatingDifferences: animatingDifferences,
|
||||
performUpdates: { collectionView, changeset, setSections in
|
||||
|
||||
self.legacyDataSource.apply(
|
||||
diffableSnapshot as! Internals.DiffableDataSourceSnapshot,
|
||||
view: self.collectionView,
|
||||
animatingDifferences: animatingDifferences,
|
||||
performUpdates: { collectionView, changeset, setSections in
|
||||
|
||||
collectionView.reload(
|
||||
using: changeset,
|
||||
setData: setSections
|
||||
)
|
||||
}
|
||||
)
|
||||
// }
|
||||
collectionView.reload(
|
||||
using: changeset,
|
||||
setData: setSections
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,14 +141,7 @@ extension DiffableDataSource {
|
||||
@nonobjc
|
||||
public func itemID(for indexPath: IndexPath) -> O.ObjectID? {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.itemIdentifier(for: indexPath)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.itemIdentifier(for: indexPath)
|
||||
// }
|
||||
return self.dispatcher.itemIdentifier(for: indexPath)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,14 +153,7 @@ extension DiffableDataSource {
|
||||
@nonobjc
|
||||
public func indexPath(for itemID: O.ObjectID) -> IndexPath? {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.indexPath(for: itemIdentifier)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.indexPath(for: itemID)
|
||||
// }
|
||||
return self.dispatcher.indexPath(for: itemID)
|
||||
}
|
||||
|
||||
|
||||
@@ -209,52 +162,31 @@ extension DiffableDataSource {
|
||||
@objc
|
||||
public dynamic func numberOfSections(in collectionView: UICollectionView) -> Int {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.numberOfSections(in: tableView)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.numberOfSections()
|
||||
// }
|
||||
return self.dispatcher.numberOfSections()
|
||||
}
|
||||
|
||||
@objc
|
||||
public dynamic func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.tableView(tableView, numberOfRowsInSection: section)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.numberOfItems(inSection: section)
|
||||
// }
|
||||
return self.dispatcher.numberOfItems(inSection: section)
|
||||
}
|
||||
|
||||
@objc
|
||||
open dynamic func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.tableView(tableView, cellForRowAt: indexPath)
|
||||
// }
|
||||
// else {
|
||||
guard let objectID = self.dispatcher.itemIdentifier(for: indexPath) else {
|
||||
|
||||
guard let objectID = self.legacyDataSource.itemIdentifier(for: indexPath) else {
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) already removed from list")
|
||||
}
|
||||
guard let object = self.dataStack.fetchExisting(objectID) as O? else {
|
||||
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) already removed from list")
|
||||
}
|
||||
guard let object = self.dataStack.fetchExisting(objectID) as O? else {
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) has been deleted")
|
||||
}
|
||||
guard let cell = self.cellProvider(collectionView, indexPath, object) else {
|
||||
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) has been deleted")
|
||||
}
|
||||
guard let cell = self.cellProvider(collectionView, indexPath, object) else {
|
||||
|
||||
Internals.abort("\(Internals.typeName(UICollectionViewDataSource.self)) returned a `nil` cell for \(Internals.typeName(IndexPath.self)) \(indexPath)")
|
||||
}
|
||||
return cell
|
||||
// }
|
||||
Internals.abort("\(Internals.typeName(UICollectionViewDataSource.self)) returned a `nil` cell for \(Internals.typeName(IndexPath.self)) \(indexPath)")
|
||||
}
|
||||
return cell
|
||||
}
|
||||
|
||||
@objc
|
||||
@@ -275,18 +207,7 @@ extension DiffableDataSource {
|
||||
private let dataStack: DataStack
|
||||
private let cellProvider: (UICollectionView, IndexPath, O) -> UICollectionViewCell?
|
||||
private let supplementaryViewProvider: (UICollectionView, String, IndexPath) -> UICollectionReusableView?
|
||||
private var rawDataSource: Any!
|
||||
|
||||
// @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
|
||||
// private var modernDataSource: UITableViewDiffableDataSource<String, O.ObjectID> {
|
||||
//
|
||||
// return self.rawDataSource as! UITableViewDiffableDataSource<String, O.ObjectID>
|
||||
// }
|
||||
|
||||
private var legacyDataSource: Internals.DiffableDataUIDispatcher<O> {
|
||||
|
||||
return self.rawDataSource as! Internals.DiffableDataUIDispatcher<O>
|
||||
}
|
||||
private let dispatcher: Internals.DiffableDataUIDispatcher<O>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,19 +261,28 @@ extension UICollectionView {
|
||||
}
|
||||
if !changeset.elementDeleted.isEmpty {
|
||||
|
||||
self.deleteItems(at: changeset.elementDeleted.map { IndexPath(row: $0.element, section: $0.section) })
|
||||
self.deleteItems(
|
||||
at: changeset.elementDeleted.map { IndexPath(item: $0.element, section: $0.section) }
|
||||
)
|
||||
}
|
||||
if !changeset.elementInserted.isEmpty {
|
||||
|
||||
self.insertItems(at: changeset.elementInserted.map { IndexPath(row: $0.element, section: $0.section) })
|
||||
self.insertItems(
|
||||
at: changeset.elementInserted.map { IndexPath(item: $0.element, section: $0.section) }
|
||||
)
|
||||
}
|
||||
if !changeset.elementUpdated.isEmpty {
|
||||
|
||||
self.reloadItems(at: changeset.elementUpdated.map { IndexPath(row: $0.element, section: $0.section) })
|
||||
self.reloadItems(
|
||||
at: changeset.elementUpdated.map { IndexPath(item: $0.element, section: $0.section) }
|
||||
)
|
||||
}
|
||||
for (source, target) in changeset.elementMoved {
|
||||
|
||||
self.moveItem(at: IndexPath(row: source.element, section: source.section), to: IndexPath(row: target.element, section: target.section))
|
||||
self.moveItem(
|
||||
at: IndexPath(item: source.element, section: source.section),
|
||||
to: IndexPath(item: target.element, section: target.section)
|
||||
)
|
||||
}
|
||||
},
|
||||
completion: nil
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// DiffableDataSource.TableView.swift
|
||||
// DiffableDataSource.TableView-UIKit.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2018 John Rommel Estropia
|
||||
@@ -23,7 +23,7 @@
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && (os(iOS) || os(tvOS))
|
||||
|
||||
import UIKit
|
||||
import CoreData
|
||||
@@ -41,7 +41,7 @@ extension DiffableDataSource {
|
||||
```
|
||||
self.dataSource = DiffableDataSource.TableView<Person>(
|
||||
tableView: self.tableView,
|
||||
dataStack: Shared.defaultStack,
|
||||
dataStack: CoreStoreDefaults.dataStack,
|
||||
cellProvider: { (tableView, indexPath, person) in
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "PersonCell") as! PersonCell
|
||||
cell.setPerson(person)
|
||||
@@ -83,7 +83,7 @@ extension DiffableDataSource {
|
||||
```
|
||||
self.dataSource = DiffableDataSource.TableView<Person>(
|
||||
tableView: self.tableView,
|
||||
dataStack: Shared.defaultStack,
|
||||
dataStack: CoreStoreDefaults.dataStack,
|
||||
cellProvider: { (tableView, indexPath, person) in
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "PersonCell") as! PersonCell
|
||||
cell.setPerson(person)
|
||||
@@ -101,31 +101,9 @@ extension DiffableDataSource {
|
||||
self.tableView = tableView
|
||||
self.cellProvider = cellProvider
|
||||
self.dataStack = dataStack
|
||||
self.dispatcher = Internals.DiffableDataUIDispatcher<O>(dataStack: dataStack)
|
||||
|
||||
super.init()
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// self.rawDataSource = UITableViewDiffableDataSource<String, O.ObjectID>(
|
||||
// tableView: tableView,
|
||||
// cellProvider: { [weak self] (tableView, indexPath, objectID) -> UITableViewCell? in
|
||||
//
|
||||
// guard let self = self else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// guard let object = self.dataStack.fetchExisting(objectID) as O? else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return self.cellProvider(tableView, indexPath, object)
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
// else {
|
||||
|
||||
self.rawDataSource = Internals.DiffableDataUIDispatcher<O>(dataStack: dataStack)
|
||||
// }
|
||||
|
||||
tableView.dataSource = self
|
||||
}
|
||||
@@ -159,7 +137,7 @@ extension DiffableDataSource {
|
||||
// }
|
||||
// else {
|
||||
|
||||
self.legacyDataSource.apply(
|
||||
self.dispatcher.apply(
|
||||
diffableSnapshot as! Internals.DiffableDataSourceSnapshot,
|
||||
view: self.tableView,
|
||||
animatingDifferences: animatingDifferences,
|
||||
@@ -184,14 +162,7 @@ extension DiffableDataSource {
|
||||
@nonobjc
|
||||
public func itemID(for indexPath: IndexPath) -> O.ObjectID? {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.itemIdentifier(for: indexPath)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.itemIdentifier(for: indexPath)
|
||||
// }
|
||||
return self.dispatcher.itemIdentifier(for: indexPath)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,14 +174,7 @@ extension DiffableDataSource {
|
||||
@nonobjc
|
||||
public func indexPath(for itemID: O.ObjectID) -> IndexPath? {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.indexPath(for: itemIdentifier)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.indexPath(for: itemID)
|
||||
// }
|
||||
return self.dispatcher.indexPath(for: itemID)
|
||||
}
|
||||
|
||||
|
||||
@@ -219,78 +183,43 @@ extension DiffableDataSource {
|
||||
@objc
|
||||
public dynamic func numberOfSections(in tableView: UITableView) -> Int {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.numberOfSections(in: tableView)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.numberOfSections()
|
||||
// }
|
||||
return self.dispatcher.numberOfSections()
|
||||
}
|
||||
|
||||
@objc
|
||||
public dynamic func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.tableView(tableView, numberOfRowsInSection: section)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.numberOfItems(inSection: section)
|
||||
// }
|
||||
return self.dispatcher.numberOfItems(inSection: section)
|
||||
}
|
||||
|
||||
@objc
|
||||
open dynamic func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.snapshot().sectionIdentifiers[section]
|
||||
// }
|
||||
// else {
|
||||
|
||||
return self.legacyDataSource.sectionIdentifier(inSection: section)
|
||||
// }
|
||||
return self.dispatcher.sectionIdentifier(inSection: section)
|
||||
}
|
||||
|
||||
@objc
|
||||
open dynamic func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.tableView(tableView, titleForFooterInSection: section)
|
||||
// }
|
||||
// else {
|
||||
|
||||
return nil
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
|
||||
@objc
|
||||
open dynamic func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
|
||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
||||
//
|
||||
// return self.modernDataSource.tableView(tableView, cellForRowAt: indexPath)
|
||||
// }
|
||||
// else {
|
||||
|
||||
guard let objectID = self.legacyDataSource.itemIdentifier(for: indexPath) else {
|
||||
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) already removed from list")
|
||||
}
|
||||
guard let object = self.dataStack.fetchExisting(objectID) as O? else {
|
||||
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) has been deleted")
|
||||
}
|
||||
guard let cell = self.cellProvider(tableView, indexPath, object) else {
|
||||
|
||||
Internals.abort("\(Internals.typeName(UITableViewDataSource.self)) returned a `nil` cell for \(Internals.typeName(IndexPath.self)) \(indexPath)")
|
||||
}
|
||||
return cell
|
||||
// }
|
||||
guard let objectID = self.dispatcher.itemIdentifier(for: indexPath) else {
|
||||
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) already removed from list")
|
||||
}
|
||||
guard let object = self.dataStack.fetchExisting(objectID) as O? else {
|
||||
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) has been deleted")
|
||||
}
|
||||
guard let cell = self.cellProvider(tableView, indexPath, object) else {
|
||||
|
||||
Internals.abort("\(Internals.typeName(UITableViewDataSource.self)) returned a `nil` cell for \(Internals.typeName(IndexPath.self)) \(indexPath)")
|
||||
}
|
||||
return cell
|
||||
}
|
||||
|
||||
@objc
|
||||
@@ -321,19 +250,7 @@ extension DiffableDataSource {
|
||||
private let cellProvider: (UITableView, IndexPath, O) -> UITableViewCell?
|
||||
|
||||
@nonobjc
|
||||
private var rawDataSource: Any!
|
||||
|
||||
// @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
|
||||
// private var modernDataSource: UITableViewDiffableDataSource<String, O.ObjectID> {
|
||||
//
|
||||
// return self.rawDataSource as! UITableViewDiffableDataSource<String, O.ObjectID>
|
||||
// }
|
||||
|
||||
@nonobjc
|
||||
private var legacyDataSource: Internals.DiffableDataUIDispatcher<O> {
|
||||
|
||||
return self.rawDataSource as! Internals.DiffableDataUIDispatcher<O>
|
||||
}
|
||||
private let dispatcher: Internals.DiffableDataUIDispatcher<O>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
#if os(iOS) || os(tvOS) || os(macOS)
|
||||
|
||||
// MARK: - DiffableDataSource
|
||||
|
||||
@@ -30,3 +31,5 @@
|
||||
Namespace for diffable data source types. See `DiffableDataSource.TableView` and `DiffableDataSource.CollectionView` for actual implementations
|
||||
*/
|
||||
public enum DiffableDataSource {}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,7 +44,7 @@ import ObjectiveC
|
||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||
}
|
||||
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
CoreStoreSchema(
|
||||
modelVersion: "V1",
|
||||
entities: [
|
||||
|
||||
@@ -23,9 +23,12 @@
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
#if canImport(SwiftUI)
|
||||
#if canImport(SwiftUI) && canImport(Combine)
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
import CoreData
|
||||
|
||||
|
||||
// MARK: - EnvironmentValues
|
||||
@@ -64,7 +67,7 @@ extension EnvironmentValues {
|
||||
|
||||
fileprivate static var defaultValue: DataStack {
|
||||
|
||||
return Shared.defaultStack
|
||||
return CoreStoreDefaults.dataStack
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import CoreData
|
||||
// ...
|
||||
}
|
||||
|
||||
CoreStore.perform(
|
||||
dataStack.perform(
|
||||
asynchronous: { (transaction) -> Void in
|
||||
let json: NSDictionary = // ...
|
||||
let person = try transaction.importObject(
|
||||
|
||||
@@ -38,7 +38,7 @@ import CoreData
|
||||
// ...
|
||||
}
|
||||
|
||||
CoreStore.perform(
|
||||
dataStack.perform(
|
||||
asynchronous: { (transaction) -> Void in
|
||||
let json: NSDictionary = // ...
|
||||
let person = try transaction.importUniqueObject(
|
||||
|
||||
@@ -568,10 +568,4 @@ extension Internals {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSDiffableDataSourceSnapshot: DiffableDataSourceSnapshotProtocol
|
||||
|
||||
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 15.0, *)
|
||||
extension NSDiffableDataSourceSnapshot: DiffableDataSourceSnapshotProtocol where SectionIdentifierType == String, ItemIdentifierType == NSManagedObjectID {}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@ import Foundation
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname == "John"))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.nickname == "John"))
|
||||
```
|
||||
*/
|
||||
public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ keyPath: KeyPath<O, V>, _ value: V) -> Where<O> {
|
||||
@@ -43,7 +43,7 @@ public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname != "John"))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.nickname != "John"))
|
||||
```
|
||||
*/
|
||||
public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ keyPath: KeyPath<O, V>, _ value: V) -> Where<O> {
|
||||
@@ -54,7 +54,7 @@ public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains the value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname))
|
||||
```
|
||||
*/
|
||||
public func ~= <O: NSManagedObject, V: QueryableAttributeType & Equatable, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, V>) -> Where<O> where S.Iterator.Element == V {
|
||||
@@ -68,7 +68,7 @@ public func ~= <O: NSManagedObject, V: QueryableAttributeType & Equatable, S: Se
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname == "John"))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.nickname == "John"))
|
||||
```
|
||||
*/
|
||||
public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ keyPath: KeyPath<O, Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -79,7 +79,7 @@ public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname != "John"))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.nickname != "John"))
|
||||
```
|
||||
*/
|
||||
public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ keyPath: KeyPath<O, Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -90,7 +90,7 @@ public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains the value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname))
|
||||
```
|
||||
*/
|
||||
public func ~= <O: NSManagedObject, V: QueryableAttributeType & Equatable, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, Optional<V>>) -> Where<O> where S.Iterator.Element == V {
|
||||
@@ -104,7 +104,7 @@ public func ~= <O: NSManagedObject, V: QueryableAttributeType & Equatable, S: Se
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age < 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age < 20))
|
||||
```
|
||||
*/
|
||||
public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, V>, _ value: V) -> Where<O> {
|
||||
@@ -115,7 +115,7 @@ public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age > 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age > 20))
|
||||
```
|
||||
*/
|
||||
public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, V>, _ value: V) -> Where<O> {
|
||||
@@ -126,7 +126,7 @@ public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age <= 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age <= 20))
|
||||
```
|
||||
*/
|
||||
public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, V>, _ value: V) -> Where<O> {
|
||||
@@ -137,7 +137,7 @@ public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age >= 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age >= 20))
|
||||
```
|
||||
*/
|
||||
public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, V>, _ value: V) -> Where<O> {
|
||||
@@ -151,7 +151,7 @@ public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age < 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age < 20))
|
||||
```
|
||||
*/
|
||||
public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -169,7 +169,7 @@ public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age > 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age > 20))
|
||||
```
|
||||
*/
|
||||
public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -187,7 +187,7 @@ public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age <= 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age <= 20))
|
||||
```
|
||||
*/
|
||||
public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -205,7 +205,7 @@ public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age >= 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age >= 20))
|
||||
```
|
||||
*/
|
||||
public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -226,7 +226,7 @@ public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master == john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||
```
|
||||
*/
|
||||
public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>, _ object: D) -> Where<O> {
|
||||
@@ -237,7 +237,7 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master != john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||
```
|
||||
*/
|
||||
public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>, _ object: D) -> Where<O> {
|
||||
@@ -248,7 +248,7 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains a value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
```
|
||||
*/
|
||||
public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, D>) -> Where<O> where S.Iterator.Element == D {
|
||||
@@ -259,7 +259,7 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master == john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||
```
|
||||
*/
|
||||
public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>, _ objectID: NSManagedObjectID) -> Where<O> {
|
||||
@@ -270,7 +270,7 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master != john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||
```
|
||||
*/
|
||||
public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>, _ objectID: NSManagedObjectID) -> Where<O> {
|
||||
@@ -281,7 +281,7 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains a value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
```
|
||||
*/
|
||||
public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, D>) -> Where<O> where S.Iterator.Element == NSManagedObjectID {
|
||||
@@ -295,7 +295,7 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master == john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||
```
|
||||
*/
|
||||
public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ object: D?) -> Where<O> {
|
||||
@@ -306,7 +306,7 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master != john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||
```
|
||||
*/
|
||||
public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ object: D?) -> Where<O> {
|
||||
@@ -317,7 +317,7 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains a value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
```
|
||||
*/
|
||||
public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, Optional<D>>) -> Where<O> where S.Iterator.Element == D {
|
||||
@@ -328,7 +328,7 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master == john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||
```
|
||||
*/
|
||||
public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ objectID: NSManagedObjectID) -> Where<O> {
|
||||
@@ -339,7 +339,7 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master != john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||
```
|
||||
*/
|
||||
public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ objectID: NSManagedObjectID) -> Where<O> {
|
||||
@@ -350,7 +350,7 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains a value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
```
|
||||
*/
|
||||
public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, Optional<D>>) -> Where<O> where S.Iterator.Element == NSManagedObjectID {
|
||||
@@ -364,7 +364,7 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname == "John"))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.nickname == "John"))
|
||||
```
|
||||
*/
|
||||
public func == <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, _ value: V) -> Where<O> {
|
||||
@@ -375,7 +375,7 @@ public func == <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, _ va
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname != "John"))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.nickname != "John"))
|
||||
```
|
||||
*/
|
||||
public func != <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, _ value: V) -> Where<O> {
|
||||
@@ -386,7 +386,7 @@ public func != <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, _ va
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains the value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname))
|
||||
```
|
||||
*/
|
||||
public func ~= <O, V, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>) -> Where<O> where S.Iterator.Element == V {
|
||||
@@ -400,7 +400,7 @@ public func ~= <O, V, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, ValueCon
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname == "John"))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.nickname == "John"))
|
||||
```
|
||||
*/
|
||||
public func == <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -411,7 +411,7 @@ public func == <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ va
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname != "John"))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.nickname != "John"))
|
||||
```
|
||||
*/
|
||||
public func != <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -422,7 +422,7 @@ public func != <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ va
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains the value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname))
|
||||
```
|
||||
*/
|
||||
public func ~= <O, V, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>) -> Where<O> where S.Iterator.Element == V {
|
||||
@@ -436,7 +436,7 @@ public func ~= <O, V, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, ValueCon
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age < 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age < 20))
|
||||
```
|
||||
*/
|
||||
public func < <O, V: Comparable>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, _ value: V) -> Where<O> {
|
||||
@@ -447,7 +447,7 @@ public func < <O, V: Comparable>(_ keyPath: KeyPath<O, ValueContainer<O>.Require
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age > 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age > 20))
|
||||
```
|
||||
*/
|
||||
public func > <O, V: Comparable>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, _ value: V) -> Where<O> {
|
||||
@@ -458,7 +458,7 @@ public func > <O, V: Comparable>(_ keyPath: KeyPath<O, ValueContainer<O>.Require
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age <= 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age <= 20))
|
||||
```
|
||||
*/
|
||||
public func <= <O, V: Comparable>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, _ value: V) -> Where<O> {
|
||||
@@ -469,7 +469,7 @@ public func <= <O, V: Comparable>(_ keyPath: KeyPath<O, ValueContainer<O>.Requir
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age >= 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age >= 20))
|
||||
```
|
||||
*/
|
||||
public func >= <O, V: Comparable>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, _ value: V) -> Where<O> {
|
||||
@@ -483,7 +483,7 @@ public func >= <O, V: Comparable>(_ keyPath: KeyPath<O, ValueContainer<O>.Requir
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age < 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age < 20))
|
||||
```
|
||||
*/
|
||||
public func < <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -501,7 +501,7 @@ public func < <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ val
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age > 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age > 20))
|
||||
```
|
||||
*/
|
||||
public func > <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -519,7 +519,7 @@ public func > <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ val
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age <= 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age <= 20))
|
||||
```
|
||||
*/
|
||||
public func <= <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -537,7 +537,7 @@ public func <= <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ va
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age >= 20))
|
||||
let person = dataStack.fetchOne(From<Person>().where(\.age >= 20))
|
||||
```
|
||||
*/
|
||||
public func >= <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ value: V?) -> Where<O> {
|
||||
@@ -558,7 +558,7 @@ public func >= <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ va
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master == john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||
```
|
||||
*/
|
||||
public func == <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, _ object: D) -> Where<O> {
|
||||
@@ -569,7 +569,7 @@ public func == <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>,
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master == john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||
```
|
||||
*/
|
||||
public func == <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, _ object: D?) -> Where<O> {
|
||||
@@ -580,7 +580,7 @@ public func == <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>,
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master != john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||
```
|
||||
*/
|
||||
public func != <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, _ object: D) -> Where<O> {
|
||||
@@ -591,7 +591,7 @@ public func != <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>,
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master != john))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||
```
|
||||
*/
|
||||
public func != <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, _ object: D?) -> Where<O> {
|
||||
@@ -602,7 +602,7 @@ public func != <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>,
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains a value of a property
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where([john, bob, joe] ~= \.master))
|
||||
```
|
||||
*/
|
||||
public func ~= <O, D, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>) -> Where<O> where S.Iterator.Element == D {
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
The `ListMonitor` monitors changes to a list of `DynamicObject` instances. Observers that implement the `ListObserver` protocol may then register themselves to the `ListMonitor`'s `addObserver(_:)` method:
|
||||
```
|
||||
let monitor = CoreStore.monitorList(
|
||||
let monitor = dataStack.monitorList(
|
||||
From<Person>(),
|
||||
Where("title", isEqualTo: "Engineer"),
|
||||
OrderBy(.ascending("lastName"))
|
||||
@@ -50,7 +50,7 @@ import CoreData
|
||||
|
||||
Creating a sectioned-list is also possible with the `monitorSectionedList(...)` method:
|
||||
```
|
||||
let monitor = CoreStore.monitorSectionedList(
|
||||
let monitor = dataStack.monitorSectionedList(
|
||||
From<Person>(),
|
||||
SectionBy("age") { "Age \($0)" },
|
||||
Where("title", isEqualTo: "Engineer"),
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
Implement the `ListObserver` protocol to observe changes to a list of `NSManagedObject`s. `ListObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
||||
```
|
||||
let monitor = CoreStore.monitorList(
|
||||
let monitor = dataStack.monitorList(
|
||||
From<Person>(),
|
||||
OrderBy(.ascending("lastName"))
|
||||
)
|
||||
@@ -96,7 +96,7 @@ extension ListObserver {
|
||||
/**
|
||||
Implement the `ListObjectObserver` protocol to observe detailed changes to a list's object. `ListObjectObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
||||
```
|
||||
let monitor = CoreStore.monitorList(
|
||||
let monitor = dataStack.monitorList(
|
||||
From<MyPersonEntity>(),
|
||||
OrderBy(.ascending("lastName"))
|
||||
)
|
||||
@@ -169,7 +169,7 @@ extension ListObjectObserver {
|
||||
/**
|
||||
Implement the `ListSectionObserver` protocol to observe changes to a list's section info. `ListSectionObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
||||
```
|
||||
let monitor = CoreStore.monitorSectionedList(
|
||||
let monitor = dataStack.monitorSectionedList(
|
||||
From<MyPersonEntity>(),
|
||||
SectionBy("age") { "Age \($0)" },
|
||||
OrderBy(.ascending("lastName"))
|
||||
|
||||
@@ -41,7 +41,7 @@ import SwiftUI
|
||||
/**
|
||||
`ListPublisher` tracks a diffable list of `DynamicObject` instances. Unlike `ListMonitor`s, `ListPublisher` are more lightweight and access objects lazily. Objects that need to be notified of `ListPublisher` changes may register themselves to its `addObserver(_:_:)` method:
|
||||
```
|
||||
let listPublisher = Shared.defaultStack.listPublisher(
|
||||
let listPublisher = CoreStoreDefaults.dataStack.listPublisher(
|
||||
From<Person>()
|
||||
.where(\.title == "Engineer")
|
||||
.orderBy(.ascending(\.lastName))
|
||||
@@ -55,7 +55,7 @@ import SwiftUI
|
||||
|
||||
`ListPublisher`s may optionally be created with sections:
|
||||
```
|
||||
let listPublisher = Shared.defaultStack.listPublisher(
|
||||
let listPublisher = CoreStoreDefaults.dataStack.listPublisher(
|
||||
From<Person>()
|
||||
.sectionBy(\.age") { "Age \($0)" }
|
||||
.where(\.title == "Engineer")
|
||||
|
||||
@@ -33,7 +33,7 @@ import Foundation
|
||||
`MigrationResult.success` indicates either the migration succeeded, or there were no migrations needed. The associated value is an array of `MigrationType`s reflecting the migration steps completed.
|
||||
`MigrationResult.failure` indicates that the migration failed. The associated object for this value is the a `CoreStoreError` enum value.
|
||||
```
|
||||
CoreStore.upgradeStorageIfNeeded(SQLiteStorage(fileName: "data.sqlite")) { (result) in
|
||||
dataStack.upgradeStorageIfNeeded(SQLiteStorage(fileName: "data.sqlite")) { (result) in
|
||||
switch result {
|
||||
case .success(let migrationSteps):
|
||||
// ...
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
The `ObjectMonitor` monitors changes to a single `DynamicObject` instance. Observers that implement the `ObjectObserver` protocol may then register themselves to the `ObjectMonitor`'s `addObserver(_:)` method:
|
||||
```
|
||||
let monitor = CoreStore.monitorObject(object)
|
||||
let monitor = dataStack.monitorObject(object)
|
||||
monitor.addObserver(self)
|
||||
```
|
||||
The created `ObjectMonitor` instance needs to be held on (retained) for as long as the object needs to be observed.
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
Implement the `ObjectObserver` protocol to observe changes to a single `DynamicObject` instance. `ObjectObserver`s may register themselves to an `ObjectMonitor`'s `addObserver(_:)` method:
|
||||
```
|
||||
let monitor = CoreStore.monitorObject(object)
|
||||
let monitor = dataStack.monitorObject(object)
|
||||
monitor.addObserver(self)
|
||||
```
|
||||
*/
|
||||
|
||||
@@ -41,7 +41,7 @@ import SwiftUI
|
||||
/**
|
||||
The `ObjectPublisher` tracks changes to a single `DynamicObject` instance. Objects that need to be notified of `ObjectPublisher` changes may register themselves to its `addObserver(_:_:)` method:
|
||||
```
|
||||
let objectPublisher = Shared.defaultStack.objectPublisher(object)
|
||||
let objectPublisher = CoreStoreDefaults.dataStack.objectPublisher(object)
|
||||
objectPublisher.addObserver(self) { (objectPublisher) in
|
||||
// Handle changes
|
||||
}
|
||||
@@ -307,6 +307,7 @@ extension ObjectPublisher {
|
||||
#if canImport(Combine)
|
||||
|
||||
#if canImport(SwiftUI)
|
||||
|
||||
withAnimation {
|
||||
|
||||
self.objectWillChange.send()
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
The `SectionBy` clause indicates the key path to use to group the `ListMonitor` objects into sections. An optional closure can also be provided to transform the value into an appropriate section name:
|
||||
```
|
||||
let monitor = CoreStore.monitorSectionedList(
|
||||
let monitor = dataStack.monitorSectionedList(
|
||||
From<Person>(),
|
||||
SectionBy("age") { "Age \($0)" },
|
||||
OrderBy(.ascending("lastName"))
|
||||
|
||||
@@ -57,7 +57,7 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
/**
|
||||
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute. A shorter way to do the same is to assign from the string keypath directly:
|
||||
```
|
||||
let fullName = CoreStore.queryValue(
|
||||
let fullName = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<String>(.attribute("fullName")),
|
||||
Where("employeeID", isEqualTo: 1111)
|
||||
@@ -65,7 +65,7 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
```
|
||||
is equivalent to:
|
||||
```
|
||||
let fullName = CoreStore.queryValue(
|
||||
let fullName = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<String>("fullName"),
|
||||
Where("employeeID", isEqualTo: 1111)
|
||||
@@ -82,7 +82,7 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
/**
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
|
||||
```
|
||||
let averageAge = CoreStore.queryValue(
|
||||
let averageAge = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.average("age"))
|
||||
)
|
||||
@@ -104,7 +104,7 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
/**
|
||||
Provides a `SelectTerm` to a `Select` clause for a count query.
|
||||
```
|
||||
let numberOfEmployees = CoreStore.queryValue(
|
||||
let numberOfEmployees = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.count("employeeID"))
|
||||
)
|
||||
@@ -126,7 +126,7 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
/**
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
|
||||
```
|
||||
let maximumAge = CoreStore.queryValue(
|
||||
let maximumAge = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.maximum("age"))
|
||||
)
|
||||
@@ -148,7 +148,7 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
/**
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
|
||||
```
|
||||
let minimumAge = CoreStore.queryValue(
|
||||
let minimumAge = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.minimum("age"))
|
||||
)
|
||||
@@ -170,7 +170,7 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
/**
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
|
||||
```
|
||||
let totalAge = CoreStore.queryValue(
|
||||
let totalAge = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.sum("age"))
|
||||
)
|
||||
@@ -192,7 +192,7 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
/**
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the `NSManagedObjectID`.
|
||||
```
|
||||
let objectID = CoreStore.queryValue(
|
||||
let objectID = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<NSManagedObjectID>(),
|
||||
Where("employeeID", isEqualTo: 1111)
|
||||
@@ -651,14 +651,14 @@ extension SelectTerm where D: CoreStoreObject {
|
||||
|
||||
You can bind the return type by specializing the initializer:
|
||||
```
|
||||
let maximumAge = CoreStore.queryValue(
|
||||
let maximumAge = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.maximum("age"))
|
||||
)
|
||||
```
|
||||
or by casting the type of the return value:
|
||||
```
|
||||
let maximumAge: Int = CoreStore.queryValue(
|
||||
let maximumAge: Int = dataStack.queryValue(
|
||||
From<MyPersonEntity>(),
|
||||
Select(.maximum("age"))
|
||||
)
|
||||
|
||||
@@ -34,7 +34,7 @@ import CoreData
|
||||
`SetupResult.success` indicates that the storage setup succeeded. The associated object for this `enum` value is the related `StorageInterface` instance.
|
||||
`SetupResult.failure` indicates that the storage setup failed. The associated object for this value is the related `CoreStoreError` enum value.
|
||||
```
|
||||
try! CoreStore.addStorage(
|
||||
try! dataStack.addStorage(
|
||||
SQLiteStore(),
|
||||
completion: { (result: SetupResult) -> Void in
|
||||
switch result {
|
||||
|
||||
@@ -30,7 +30,7 @@ import CoreData
|
||||
// MARK: - SynchronousDataTransaction
|
||||
|
||||
/**
|
||||
The `SynchronousDataTransaction` provides an interface for `DynamicObject` creates, updates, and deletes. A transaction object should typically be only used from within a transaction block initiated from `DataStack.beginSynchronous(_:)`, or from `CoreStore.beginSynchronous(_:)`.
|
||||
The `SynchronousDataTransaction` provides an interface for `DynamicObject` creates, updates, and deletes. A transaction object should typically be only used from within a transaction block initiated from `DataStack.beginSynchronous(_:)`.
|
||||
*/
|
||||
public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class UnsafeDataModelSchema: DynamicSchema {
|
||||
/**
|
||||
Initializes a `UnsafeDataModelSchema` from an `NSManagedObjectModel`.
|
||||
```
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
UnsafeDataModelSchema(modelName: "MyAppV1", model: model)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -34,7 +34,7 @@ import Foundation
|
||||
enum Static {
|
||||
static var myDataKey: Void?
|
||||
}
|
||||
CoreStore.defaultStack.userInfo[&Static.myDataKey] = myObject
|
||||
CoreStoreDefaults.dataStack.userInfo[&Static.myDataKey] = myObject
|
||||
```
|
||||
- Important: Do not use this class to store thread-sensitive data.
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ public final class UserInfo {
|
||||
enum Static {
|
||||
static var myDataKey: Void?
|
||||
}
|
||||
CoreStore.defaultStack.userInfo[&Static.myDataKey] = myObject
|
||||
CoreStoreDefaults.dataStack.userInfo[&Static.myDataKey] = myObject
|
||||
```
|
||||
- Important: Do not use this method to store thread-sensitive data.
|
||||
- parameter key: the key for custom data. Make sure this is a static pointer that will never be changed.
|
||||
@@ -79,7 +79,7 @@ public final class UserInfo {
|
||||
enum Static {
|
||||
static var myDataKey: Void?
|
||||
}
|
||||
CoreStore.defaultStack.userInfo[&Static.myDataKey, lazyInit: { MyObject() }] = myObject
|
||||
CoreStoreDefaults.dataStack.userInfo[&Static.myDataKey, lazyInit: { MyObject() }] = myObject
|
||||
```
|
||||
- Important: Do not use this method to store thread-sensitive data.
|
||||
- parameter key: the key for custom data. Make sure this is a static pointer that will never be changed.
|
||||
|
||||
@@ -41,7 +41,7 @@ import Foundation
|
||||
let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
|
||||
}
|
||||
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
CoreStoreSchema(
|
||||
modelVersion: "V1",
|
||||
entities: [
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let owner = CoreStore.fetchOne(
|
||||
let owner = dataStack.fetchOne(
|
||||
From<Pet>().where(
|
||||
(\.master ~ \.name) == "John"
|
||||
)
|
||||
@@ -60,7 +60,7 @@ extension Where {
|
||||
Type-safe keyPath chain usable in query/fetch expressions.
|
||||
```
|
||||
let expression: Where<Pet>.Expression = (\.master ~ \.name)
|
||||
let owner = CoreStore.fetchOne(
|
||||
let owner = dataStack.fetchOne(
|
||||
From<Pet>().where(expression == "John")
|
||||
)
|
||||
```
|
||||
@@ -130,7 +130,7 @@ extension Where {
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let owner = CoreStore.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func ~<D: NSManagedObject, O: NSManagedObject, V: AllowedObjectiveCKeyPathValue>(_ lhs: KeyPath<D, O>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<Where<D>.SingleTarget, V> {
|
||||
@@ -141,7 +141,7 @@ public func ~<D: NSManagedObject, O: NSManagedObject, V: AllowedObjectiveCKeyPat
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let owner = CoreStore.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: NSManagedObject, O: NSManagedObject, V: AllowedObjectiveCKeyPathValue>(_ lhs: KeyPath<D, O?>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<Where<D>.SingleTarget, V> {
|
||||
@@ -152,7 +152,7 @@ public func ~ <D: NSManagedObject, O: NSManagedObject, V: AllowedObjectiveCKeyPa
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let happyPets = CoreStore.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: NSManagedObject, O: NSManagedObject, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(_ lhs: KeyPath<D, O>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<Where<D>.CollectionTarget, V> {
|
||||
@@ -163,7 +163,7 @@ public func ~ <D: NSManagedObject, O: NSManagedObject, V: AllowedObjectiveCToMan
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let happyPets = CoreStore.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: NSManagedObject, O: NSManagedObject, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(_ lhs: KeyPath<D, O?>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<Where<D>.CollectionTarget, V> {
|
||||
@@ -174,7 +174,7 @@ public func ~ <D: NSManagedObject, O: NSManagedObject, V: AllowedObjectiveCToMan
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let johnsSonInLaw = CoreStore.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.name) == "John"))
|
||||
let johnsSonInLaw = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: NSManagedObject, O: NSManagedObject, T, V: AllowedObjectiveCKeyPathValue>(_ lhs: Where<D>.Expression<T, O>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<T, V> {
|
||||
@@ -185,7 +185,7 @@ public func ~ <D: NSManagedObject, O: NSManagedObject, T, V: AllowedObjectiveCKe
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let johnsSonInLaw = CoreStore.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.name) == "John"))
|
||||
let johnsSonInLaw = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: NSManagedObject, O: NSManagedObject, T, V: AllowedObjectiveCKeyPathValue>(_ lhs: Where<D>.Expression<T, O?>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<T, V> {
|
||||
@@ -196,7 +196,7 @@ public func ~ <D: NSManagedObject, O: NSManagedObject, T, V: AllowedObjectiveCKe
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let spouseHasSiblings = CoreStore.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.children).count() > 0))
|
||||
let spouseHasSiblings = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.children).count() > 0))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: NSManagedObject, O: NSManagedObject, T, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(_ lhs: Where<D>.Expression<T, O>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<Where<D>.CollectionTarget, V> {
|
||||
@@ -207,7 +207,7 @@ public func ~ <D: NSManagedObject, O: NSManagedObject, T, V: AllowedObjectiveCTo
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let spouseHasSiblings = CoreStore.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.children).count() > 0))
|
||||
let spouseHasSiblings = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.children).count() > 0))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: NSManagedObject, O: NSManagedObject, T, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(_ lhs: Where<D>.Expression<T, O?>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<Where<D>.CollectionTarget, V> {
|
||||
@@ -218,7 +218,7 @@ public func ~ <D: NSManagedObject, O: NSManagedObject, T, V: AllowedObjectiveCTo
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let spousesWithBadNamingSense = CoreStore.fetchAll(From<Person>().where((\.spouse ~ \.pets ~ \.name).any() == "Spot"))
|
||||
let spousesWithBadNamingSense = dataStack.fetchAll(From<Person>().where((\.spouse ~ \.pets ~ \.name).any() == "Spot"))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: NSManagedObject, O: NSManagedObject, T, C: AllowedObjectiveCToManyRelationshipKeyPathValue, V: AllowedObjectiveCKeyPathValue>(_ lhs: Where<D>.Expression<T, C>, _ rhs: KeyPath<O, V>) -> Where<D>.Expression<Where<D>.CollectionTarget, V> {
|
||||
@@ -232,7 +232,7 @@ public func ~ <D: NSManagedObject, O: NSManagedObject, T, C: AllowedObjectiveCTo
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let owner = CoreStore.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: CoreStoreObject, O: CoreStoreObject, K: KeyPathStringConvertible>(_ lhs: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, _ rhs: KeyPath<O, K>) -> Where<D>.Expression<Where<D>.SingleTarget, K.DestinationValueType> where K.ObjectType == O {
|
||||
@@ -246,7 +246,7 @@ public func ~ <D: CoreStoreObject, O: CoreStoreObject, K: KeyPathStringConvertib
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let owner = CoreStore.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, K: KeyPathStringConvertible>(_ lhs: Where<D>.Expression<T, O>, _ rhs: KeyPath<O, K>) -> Where<D>.Expression<T, K.DestinationValueType> where K.ObjectType == O {
|
||||
@@ -260,7 +260,7 @@ public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, K: KeyPathStringConver
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let owner = CoreStore.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, K: KeyPathStringConvertible>(_ lhs: Where<D>.Expression<T, O?>, _ rhs: KeyPath<O, K>) -> Where<D>.Expression<T, K.DestinationValueType> where K.ObjectType == O {
|
||||
@@ -274,7 +274,7 @@ public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, K: KeyPathStringConver
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let happyPets = CoreStore.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: CoreStoreObject, O: CoreStoreObject, K: ToManyRelationshipKeyPathStringConvertible>(_ lhs: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, _ rhs: KeyPath<O, K>) -> Where<D>.Expression<Where<D>.CollectionTarget, K.DestinationValueType> where K.ObjectType == O {
|
||||
@@ -288,7 +288,7 @@ public func ~ <D: CoreStoreObject, O: CoreStoreObject, K: ToManyRelationshipKeyP
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let happyPets = CoreStore.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, K: ToManyRelationshipKeyPathStringConvertible>(_ lhs: Where<D>.Expression<T, O>, _ rhs: KeyPath<O, K>) -> Where<D>.Expression<Where<D>.CollectionTarget, K.DestinationValueType> where K.ObjectType == O {
|
||||
@@ -302,7 +302,7 @@ public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, K: ToManyRelationshipK
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let happyPets = CoreStore.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, K: ToManyRelationshipKeyPathStringConvertible>(_ lhs: Where<D>.Expression<T, O?>, _ rhs: KeyPath<O, K>) -> Where<D>.Expression<Where<D>.CollectionTarget, K.DestinationValueType> where K.ObjectType == O {
|
||||
@@ -316,7 +316,7 @@ public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, K: ToManyRelationshipK
|
||||
/**
|
||||
Connects multiple `KeyPathStringConvertible`s to create a type-safe chain usable in query/fetch expressions
|
||||
```
|
||||
let spousesWithBadNamingSense = CoreStore.fetchAll(From<Pet>().where((\.master ~ \.pets ~ \.name).any() == "Spot"))
|
||||
let spousesWithBadNamingSense = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets ~ \.name).any() == "Spot"))
|
||||
```
|
||||
*/
|
||||
public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, KC: ToManyRelationshipKeyPathStringConvertible, KV: ToManyRelationshipKeyPathStringConvertible>(_ lhs: Where<D>.Expression<T, KC>, _ rhs: KeyPath<O, KV>) -> Where<D>.Expression<Where<D>.CollectionTarget, KV.DestinationValueType> where KC.ObjectType == D, KV.ObjectType == O {
|
||||
@@ -333,7 +333,7 @@ public func ~ <D: CoreStoreObject, O: CoreStoreObject, T, KC: ToManyRelationship
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.name) == "John"))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func == <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V>, _ rhs: V) -> Where<D> {
|
||||
@@ -344,7 +344,7 @@ public func == <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.name) != "John"))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.name) != "John"))
|
||||
```
|
||||
*/
|
||||
public func != <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V>, _ rhs: V) -> Where<D> {
|
||||
@@ -355,7 +355,7 @@ public func != <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(["John", "Joe"] ~= (\.master ~ \.name))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(["John", "Joe"] ~= (\.master ~ \.name))
|
||||
```
|
||||
*/
|
||||
public func ~= <D, T, V: QueryableAttributeType, S: Sequence>(_ sequence: S, _ expression: Where<D>.Expression<T, V>) -> Where<D> where S.Iterator.Element == V {
|
||||
@@ -369,7 +369,7 @@ public func ~= <D, T, V: QueryableAttributeType, S: Sequence>(_ sequence: S, _ e
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is less than a value
|
||||
```
|
||||
let lonelyDog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.pets).count() < 2))
|
||||
let lonelyDog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.pets).count() < 2))
|
||||
```
|
||||
*/
|
||||
public func < <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Expression<T, V>, _ rhs: V) -> Where<D> {
|
||||
@@ -380,7 +380,7 @@ public func < <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Exp
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is less than or equal to a value
|
||||
```
|
||||
let lonelyDog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.pets).count() <= 1)
|
||||
let lonelyDog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.pets).count() <= 1)
|
||||
```
|
||||
*/
|
||||
public func <= <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Expression<T, V>, _ rhs: V) -> Where<D> {
|
||||
@@ -391,7 +391,7 @@ public func <= <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Ex
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is greater than a value
|
||||
```
|
||||
let happyDog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.pets).count() > 1)
|
||||
let happyDog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.pets).count() > 1)
|
||||
```
|
||||
*/
|
||||
public func > <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Expression<T, V>, _ rhs: V) -> Where<D> {
|
||||
@@ -402,7 +402,7 @@ public func > <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Exp
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is greater than or equal to a value
|
||||
```
|
||||
let happyDog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.pets).count() >= 2)
|
||||
let happyDog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.pets).count() >= 2)
|
||||
```
|
||||
*/
|
||||
public func >= <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Expression<T, V>, _ rhs: V) -> Where<D> {
|
||||
@@ -416,7 +416,7 @@ public func >= <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Ex
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.name) == "John"))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func == <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V?>, _ rhs: V) -> Where<D> {
|
||||
@@ -427,7 +427,7 @@ public func == <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.name) == "John"))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.name) == "John"))
|
||||
```
|
||||
*/
|
||||
public func == <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V?>, _ rhs: V?) -> Where<D> {
|
||||
@@ -438,7 +438,7 @@ public func == <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.name) != "John"))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.name) != "John"))
|
||||
```
|
||||
*/
|
||||
public func != <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V?>, _ rhs: V) -> Where<D> {
|
||||
@@ -449,7 +449,7 @@ public func != <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.name) != "John"))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where((\.master ~ \.name) != "John"))
|
||||
```
|
||||
*/
|
||||
public func != <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V?>, _ rhs: V?) -> Where<D> {
|
||||
@@ -460,7 +460,7 @@ public func != <D, T, V: QueryableAttributeType>(_ lhs: Where<D>.Expression<T, V
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(["John", "Joe"] ~= (\.master ~ \.name))
|
||||
let dog = dataStack.fetchOne(From<Dog>().where(["John", "Joe"] ~= (\.master ~ \.name))
|
||||
```
|
||||
*/
|
||||
public func ~= <D, T, V: QueryableAttributeType, S: Sequence>(_ sequence: S, _ expression: Where<D>.Expression<T, V?>) -> Where<D> where S.Iterator.Element == V {
|
||||
@@ -474,7 +474,7 @@ public func ~= <D, T, V: QueryableAttributeType, S: Sequence>(_ sequence: S, _ e
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is less than a value
|
||||
```
|
||||
let childsPet = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.age) < 10))
|
||||
let childsPet = dataStack.fetchOne(From<Dog>().where((\.master ~ \.age) < 10))
|
||||
```
|
||||
*/
|
||||
public func < <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Expression<T, V?>, _ rhs: V) -> Where<D> {
|
||||
@@ -485,7 +485,7 @@ public func < <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Exp
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is less than or equal to a value
|
||||
```
|
||||
let childsPet = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.age) <= 10))
|
||||
let childsPet = dataStack.fetchOne(From<Dog>().where((\.master ~ \.age) <= 10))
|
||||
```
|
||||
*/
|
||||
public func <= <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Expression<T, V?>, _ rhs: V?) -> Where<D> {
|
||||
@@ -496,7 +496,7 @@ public func <= <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Ex
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is greater than a value
|
||||
```
|
||||
let teensPet = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.age) > 10))
|
||||
let teensPet = dataStack.fetchOne(From<Dog>().where((\.master ~ \.age) > 10))
|
||||
```
|
||||
*/
|
||||
public func > <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Expression<T, V?>, _ rhs: V) -> Where<D> {
|
||||
@@ -507,7 +507,7 @@ public func > <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Exp
|
||||
/**
|
||||
Creates a `Where` clause by comparing if an expression is greater than or equal to a value
|
||||
```
|
||||
let teensPet = CoreStore.fetchOne(From<Dog>().where((\.master ~ \.age) >= 10))
|
||||
let teensPet = dataStack.fetchOne(From<Dog>().where((\.master ~ \.age) >= 10))
|
||||
```
|
||||
*/
|
||||
public func >= <D, T, V: QueryableAttributeType & Comparable>(_ lhs: Where<D>.Expression<T, V?>, _ rhs: V?) -> Where<D> {
|
||||
@@ -523,7 +523,7 @@ extension KeyPath where Root: NSManagedObject, Value: AllowedObjectiveCToManyRel
|
||||
/**
|
||||
Creates a `Where.Expression` clause for COUNT
|
||||
```
|
||||
let dogsWithPlaymates = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets).count() > 1))
|
||||
let dogsWithPlaymates = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func count() -> Where<Root>.Expression<Where<Root>.CollectionTarget, Int> {
|
||||
@@ -539,7 +539,7 @@ extension Where.Expression where D: NSManagedObject, T == Where<D>.CollectionTar
|
||||
/**
|
||||
Creates a `Where.Expression` clause for COUNT
|
||||
```
|
||||
let dogsWithPlaymates = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets).count() > 1))
|
||||
let dogsWithPlaymates = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func count() -> Where<D>.Expression<T, Int> {
|
||||
@@ -556,7 +556,7 @@ extension Where.Expression where D: NSManagedObject, T == Where<D>.CollectionTar
|
||||
/**
|
||||
Creates a `Where.Expression` clause for ANY
|
||||
```
|
||||
let dogsWithBadNamingSense = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.name).any() > "Spot"))
|
||||
let dogsWithBadNamingSense = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.name).any() > "Spot"))
|
||||
```
|
||||
*/
|
||||
public func any() -> Where<D>.Expression<T, V> {
|
||||
@@ -567,7 +567,7 @@ extension Where.Expression where D: NSManagedObject, T == Where<D>.CollectionTar
|
||||
/**
|
||||
Creates a `Where.Expression` clause for ALL
|
||||
```
|
||||
let allPlaymatePuppies = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.age).all() > 5))
|
||||
let allPlaymatePuppies = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.age).all() > 5))
|
||||
```
|
||||
*/
|
||||
public func all() -> Where<D>.Expression<T, V> {
|
||||
@@ -578,7 +578,7 @@ extension Where.Expression where D: NSManagedObject, T == Where<D>.CollectionTar
|
||||
/**
|
||||
Creates a `Where.Expression` clause for NONE
|
||||
```
|
||||
let dogs = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.name).any() > "Spot"))
|
||||
let dogs = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.name).any() > "Spot"))
|
||||
```
|
||||
*/
|
||||
public func none() -> Where<D>.Expression<T, V> {
|
||||
@@ -595,7 +595,7 @@ extension KeyPath where Root: CoreStoreObject, Value: ToManyRelationshipKeyPathS
|
||||
/**
|
||||
Creates a `Where.Expression` clause for COUNT
|
||||
```
|
||||
let dogsWithPlaymates = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets).count() > 1))
|
||||
let dogsWithPlaymates = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func count() -> Where<Root>.Expression<Where<Root>.CollectionTarget, Int> {
|
||||
@@ -612,7 +612,7 @@ extension Where.Expression where D: CoreStoreObject, T == Where<D>.CollectionTar
|
||||
/**
|
||||
Creates a `Where.Expression` clause for COUNT
|
||||
```
|
||||
let dogsWithPlaymates = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets).count() > 1))
|
||||
let dogsWithPlaymates = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets).count() > 1))
|
||||
```
|
||||
*/
|
||||
public func count() -> Where<D>.Expression<T, Int> {
|
||||
@@ -623,7 +623,7 @@ extension Where.Expression where D: CoreStoreObject, T == Where<D>.CollectionTar
|
||||
/**
|
||||
Creates a `Where.Expression` clause for ANY
|
||||
```
|
||||
let dogsWithBadNamingSense = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.name).any() > "Spot"))
|
||||
let dogsWithBadNamingSense = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.name).any() > "Spot"))
|
||||
```
|
||||
*/
|
||||
public func any() -> Where<D>.Expression<T, V> {
|
||||
@@ -634,7 +634,7 @@ extension Where.Expression where D: CoreStoreObject, T == Where<D>.CollectionTar
|
||||
/**
|
||||
Creates a `Where.Expression` clause for ALL
|
||||
```
|
||||
let allPlaymatePuppies = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.age).all() > 5))
|
||||
let allPlaymatePuppies = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.age).all() > 5))
|
||||
```
|
||||
*/
|
||||
public func all() -> Where<D>.Expression<T, V> {
|
||||
@@ -645,7 +645,7 @@ extension Where.Expression where D: CoreStoreObject, T == Where<D>.CollectionTar
|
||||
/**
|
||||
Creates a `Where.Expression` clause for NONE
|
||||
```
|
||||
let dogs = CoreStore.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.name).any() > "Spot"))
|
||||
let dogs = dataStack.fetchAll(From<Dog>().where((\.master ~ \.pets ~ \.name).any() > "Spot"))
|
||||
```
|
||||
*/
|
||||
public func none() -> Where<D>.Expression<T, V> {
|
||||
|
||||
@@ -32,7 +32,7 @@ import Foundation
|
||||
/**
|
||||
The `XcodeDataModelSchema` describes a model version declared in a single *.xcdatamodeld file.
|
||||
```
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
XcodeDataModelSchema(modelName: "MyAppV1", bundle: .main)
|
||||
)
|
||||
```
|
||||
@@ -109,7 +109,7 @@ public final class XcodeDataModelSchema: DynamicSchema {
|
||||
/**
|
||||
Initializes an `XcodeDataModelSchema` from an *.xcdatamodeld version name and its containing `Bundle`.
|
||||
```
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
XcodeDataModelSchema(modelName: "MyAppV1", bundle: .main)
|
||||
)
|
||||
```
|
||||
@@ -135,7 +135,7 @@ public final class XcodeDataModelSchema: DynamicSchema {
|
||||
/**
|
||||
Initializes an `XcodeDataModelSchema` from an *.xcdatamodeld file URL.
|
||||
```
|
||||
CoreStore.defaultStack = DataStack(
|
||||
CoreStoreDefaults.dataStack = DataStack(
|
||||
XcodeDataModelSchema(modelName: "MyAppV1", modelVersionFileURL: fileURL)
|
||||
)
|
||||
```
|
||||
|
||||
294
Sources/diffableDataSource.CollectionView-AppKit.swift
Normal file
294
Sources/diffableDataSource.CollectionView-AppKit.swift
Normal file
@@ -0,0 +1,294 @@
|
||||
//
|
||||
// DiffableDataSource.CollectionView-AppKit.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2018 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.
|
||||
//
|
||||
|
||||
#if canImport(AppKit) && os(macOS)
|
||||
|
||||
import AppKit
|
||||
import CoreData
|
||||
|
||||
|
||||
// MARK: - DiffableDataSource
|
||||
|
||||
extension DiffableDataSource {
|
||||
|
||||
// MARK: - CollectionView
|
||||
|
||||
/**
|
||||
The `DiffableDataSource.CollectionView` serves as a `NSCollectionViewDataSource` that handles `ListPublisher` snapshots for a `NSCollectionView`. Subclasses of `DiffableDataSource.CollectionView` may override some `NSCollectionViewDataSource` methods as needed.
|
||||
The `DiffableDataSource.CollectionView` instance needs to be held on (retained) for as long as the `NSCollectionView`'s lifecycle.
|
||||
```
|
||||
self.dataSource = DiffableDataSource.CollectionView<Person>(
|
||||
collectionView: self.collectionView,
|
||||
dataStack: CoreStoreDefaults.dataStack,
|
||||
itemProvider: { (collectionView, indexPath, person) in
|
||||
let item = collectionView.makeItem(withIdentifier: .collectionViewItem, for: indexPath) as! PersonItem
|
||||
item.setPerson(person)
|
||||
return item
|
||||
}
|
||||
)
|
||||
```
|
||||
The dataSource can then apply changes from a `ListPublisher` as shown:
|
||||
```
|
||||
listPublisher.addObserver(self) { [weak self] (listPublisher) in
|
||||
self?.dataSource?.apply(
|
||||
listPublisher.snapshot,
|
||||
animatingDifferences: true
|
||||
)
|
||||
}
|
||||
```
|
||||
`DiffableDataSource.CollectionView` fully handles the reload animations.
|
||||
*/
|
||||
open class CollectionView<O: DynamicObject>: NSObject, NSCollectionViewDataSource {
|
||||
|
||||
// MARK: Public
|
||||
|
||||
/**
|
||||
The object type represented by this dataSource
|
||||
*/
|
||||
public typealias ObjectType = O
|
||||
|
||||
/**
|
||||
Initializes the `DiffableDataSource.CollectionView`. This instance needs to be held on (retained) for as long as the `NSCollectionView`'s lifecycle.
|
||||
```
|
||||
self.dataSource = DiffableDataSource.CollectionView<Person>(
|
||||
collectionView: self.collectionView,
|
||||
dataStack: CoreStoreDefaults.dataStack,
|
||||
itemProvider: { (collectionView, indexPath, person) in
|
||||
let item = collectionView.makeItem(withIdentifier: .collectionViewItem, for: indexPath) as! PersonItem
|
||||
item.setPerson(person)
|
||||
return item
|
||||
}
|
||||
)
|
||||
```
|
||||
- parameter collectionView: the `NSCollectionView` to set the `dataSource` of. This instance is not retained by the `DiffableDataSource.CollectionView`.
|
||||
- parameter dataStack: the `DataStack` instance that the dataSource will fetch objects from
|
||||
- parameter itemProvider: a closure that configures and returns the `NSCollectionViewItem` for the object
|
||||
*/
|
||||
@nonobjc
|
||||
public init(collectionView: NSCollectionView, dataStack: DataStack, itemProvider: @escaping (NSCollectionView, IndexPath, O) -> NSCollectionViewItem?, supplementaryViewProvider: @escaping (NSCollectionView, String, IndexPath) -> NSView? = { _, _, _ in nil }) {
|
||||
|
||||
self.collectionView = collectionView
|
||||
self.itemProvider = itemProvider
|
||||
self.supplementaryViewProvider = supplementaryViewProvider
|
||||
self.dataStack = dataStack
|
||||
self.dispatcher = Internals.DiffableDataUIDispatcher<O>(dataStack: dataStack)
|
||||
|
||||
super.init()
|
||||
|
||||
collectionView.dataSource = self
|
||||
}
|
||||
|
||||
/**
|
||||
Reloads the `NSCollectionView` using a `ListSnapshot`. This is typically from the `snapshot` property of a `ListPublisher`:
|
||||
```
|
||||
listPublisher.addObserver(self) { [weak self] (listPublisher) in
|
||||
self?.dataSource?.apply(
|
||||
listPublisher.snapshot,
|
||||
animatingDifferences: true
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
- parameter snapshot: the `ListSnapshot` used to reload the `UITableView` with. This is typically from the `snapshot` property of a `ListPublisher`.
|
||||
- parameter animatingDifferences: if `true`, animations will be applied as configured by the `defaultRowAnimation` value. Defaults to `true`.
|
||||
*/
|
||||
public func apply(_ snapshot: ListSnapshot<O>, animatingDifferences: Bool = true) {
|
||||
|
||||
let diffableSnapshot = snapshot.diffableSnapshot
|
||||
self.dispatcher.apply(
|
||||
diffableSnapshot as! Internals.DiffableDataSourceSnapshot,
|
||||
view: self.collectionView,
|
||||
animatingDifferences: animatingDifferences,
|
||||
performUpdates: { collectionView, changeset, setSections in
|
||||
|
||||
collectionView.reload(
|
||||
using: changeset,
|
||||
setData: setSections
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the object identifier for the item at the specified `IndexPath`, or `nil` if not found
|
||||
|
||||
- parameter indexPath: the `IndexPath` to search for
|
||||
- returns: the object identifier for the item at the specified `IndexPath`, or `nil` if not found
|
||||
*/
|
||||
@nonobjc
|
||||
public func itemID(for indexPath: IndexPath) -> O.ObjectID? {
|
||||
|
||||
return self.dispatcher.itemIdentifier(for: indexPath)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the `IndexPath` for the item with the specified object identifier, or `nil` if not found
|
||||
|
||||
- parameter itemID: the object identifier to search for
|
||||
- returns: the `IndexPath` for the item with the specified object identifier, or `nil` if not found
|
||||
*/
|
||||
@nonobjc
|
||||
public func indexPath(for itemID: O.ObjectID) -> IndexPath? {
|
||||
|
||||
return self.dispatcher.indexPath(for: itemID)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSCollectionViewDataSource
|
||||
|
||||
@objc
|
||||
public dynamic func numberOfSections(in collectionView: NSCollectionView) -> Int {
|
||||
|
||||
return self.dispatcher.numberOfSections()
|
||||
}
|
||||
|
||||
@objc
|
||||
public dynamic func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
|
||||
return self.dispatcher.numberOfItems(inSection: section)
|
||||
}
|
||||
|
||||
@objc
|
||||
open dynamic func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
||||
|
||||
guard let objectID = self.dispatcher.itemIdentifier(for: indexPath) else {
|
||||
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) already removed from list")
|
||||
}
|
||||
guard let object = self.dataStack.fetchExisting(objectID) as O? else {
|
||||
|
||||
Internals.abort("Object at \(Internals.typeName(IndexPath.self)) \(indexPath) has been deleted")
|
||||
}
|
||||
guard let item = self.itemProvider(collectionView, indexPath, object) else {
|
||||
|
||||
Internals.abort("\(Internals.typeName(NSCollectionViewDataSource.self)) returned a `nil` item for \(Internals.typeName(IndexPath.self)) \(indexPath)")
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
@objc
|
||||
open dynamic func collectionView(_ collectionView: NSCollectionView, viewForSupplementaryElementOfKind kind: NSCollectionView.SupplementaryElementKind, at indexPath: IndexPath) -> NSView {
|
||||
|
||||
guard let view = self.supplementaryViewProvider(collectionView, kind, indexPath) else {
|
||||
|
||||
return NSView()
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private weak var collectionView: NSCollectionView?
|
||||
|
||||
private let dataStack: DataStack
|
||||
private let itemProvider: (NSCollectionView, IndexPath, O) -> NSCollectionViewItem?
|
||||
private let supplementaryViewProvider: (NSCollectionView, String, IndexPath) -> NSView?
|
||||
private let dispatcher: Internals.DiffableDataUIDispatcher<O>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSCollectionView
|
||||
|
||||
extension NSCollectionView {
|
||||
|
||||
// MARK: FilePrivate
|
||||
|
||||
@nonobjc
|
||||
fileprivate func reload<C, O>(
|
||||
using stagedChangeset: Internals.DiffableDataUIDispatcher<O>.StagedChangeset<C>,
|
||||
interrupt: ((Internals.DiffableDataUIDispatcher<O>.Changeset<C>) -> Bool)? = nil,
|
||||
setData: (C) -> Void
|
||||
) {
|
||||
|
||||
if case .none = window, let data = stagedChangeset.last?.data {
|
||||
|
||||
setData(data)
|
||||
self.reloadData()
|
||||
return
|
||||
}
|
||||
for changeset in stagedChangeset {
|
||||
|
||||
if let interrupt = interrupt, interrupt(changeset), let data = stagedChangeset.last?.data {
|
||||
|
||||
setData(data)
|
||||
self.reloadData()
|
||||
return
|
||||
}
|
||||
self.animator().performBatchUpdates(
|
||||
{
|
||||
setData(changeset.data)
|
||||
|
||||
if !changeset.sectionDeleted.isEmpty {
|
||||
|
||||
self.deleteSections(IndexSet(changeset.sectionDeleted))
|
||||
}
|
||||
if !changeset.sectionInserted.isEmpty {
|
||||
|
||||
self.insertSections(IndexSet(changeset.sectionInserted))
|
||||
}
|
||||
if !changeset.sectionUpdated.isEmpty {
|
||||
|
||||
self.reloadSections(IndexSet(changeset.sectionUpdated))
|
||||
}
|
||||
for (source, target) in changeset.sectionMoved {
|
||||
|
||||
self.moveSection(source, toSection: target)
|
||||
}
|
||||
if !changeset.elementDeleted.isEmpty {
|
||||
|
||||
self.deleteItems(
|
||||
at: Set(changeset.elementDeleted.map { IndexPath(item: $0.element, section: $0.section) })
|
||||
)
|
||||
}
|
||||
if !changeset.elementInserted.isEmpty {
|
||||
|
||||
self.insertItems(
|
||||
at: Set(changeset.elementInserted.map { IndexPath(item: $0.element, section: $0.section) })
|
||||
)
|
||||
}
|
||||
if !changeset.elementUpdated.isEmpty {
|
||||
|
||||
self.reloadItems(
|
||||
at: Set(changeset.elementUpdated.map { IndexPath(item: $0.element, section: $0.section) })
|
||||
)
|
||||
}
|
||||
for (source, target) in changeset.elementMoved {
|
||||
|
||||
self.moveItem(
|
||||
at: IndexPath(item: source.element, section: source.section),
|
||||
to: IndexPath(item: target.element, section: target.section)
|
||||
)
|
||||
}
|
||||
},
|
||||
completionHandler: nil
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user