mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-05-27 01:49:27 +02:00
Support typed errors. Misc formatting
This commit is contained in:
@@ -17,6 +17,12 @@ class Animal: CoreStoreObject {
|
|||||||
var master: Person?
|
var master: Person?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Dog: Animal {
|
||||||
|
|
||||||
|
@Field.Stored("name")
|
||||||
|
var name: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
class Person: CoreStoreObject {
|
class Person: CoreStoreObject {
|
||||||
|
|
||||||
@Field.Stored("name")
|
@Field.Stored("name")
|
||||||
@@ -33,16 +39,20 @@ let dataStack = DataStack(
|
|||||||
modelVersion: "V1",
|
modelVersion: "V1",
|
||||||
entities: [
|
entities: [
|
||||||
Entity<Animal>("Animal"),
|
Entity<Animal>("Animal"),
|
||||||
Entity<Person>("Person")
|
Entity<Person>("Person"),
|
||||||
],
|
Entity<Dog>("Dog")
|
||||||
|
]/*,
|
||||||
versionLock: [
|
versionLock: [
|
||||||
"Animal": [0x4a201cc685d53c0a, 0x16e6c3b561577875, 0xb032e2da61c792a0, 0xa133b801051acee4],
|
"Animal": [0x4a201cc685d53c0a, 0x16e6c3b561577875, 0xb032e2da61c792a0, 0xa133b801051acee4],
|
||||||
"Person": [0xca938eea1af4bd56, 0xbca30994506356ad, 0x7a7cc655898816ef, 0x1a4551ffedc9b214]
|
"Person": [0xca938eea1af4bd56, 0xbca30994506356ad, 0x7a7cc655898816ef, 0x1a4551ffedc9b214]
|
||||||
]
|
]*/
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
dataStack.addStorage(
|
dataStack.addStorage(
|
||||||
SQLiteStore(fileName: "data.sqlite"),
|
SQLiteStore(
|
||||||
|
fileName: "data.sqlite",
|
||||||
|
localStorageOptions: .recreateStoreOnModelMismatch
|
||||||
|
),
|
||||||
completion: { result in
|
completion: { result in
|
||||||
|
|
||||||
switch result {
|
switch result {
|
||||||
@@ -73,8 +83,8 @@ dataStack.addStorage(
|
|||||||
case .success:
|
case .success:
|
||||||
/// Accessing Objects =====
|
/// Accessing Objects =====
|
||||||
let bird = try! dataStack.fetchOne(
|
let bird = try! dataStack.fetchOne(
|
||||||
From<Animal>()
|
From<Dog>()
|
||||||
.where(\.$species == "Sparrow")
|
.where(\Dog.$species == "Sparrow")
|
||||||
)!
|
)!
|
||||||
print(bird.species)
|
print(bird.species)
|
||||||
print(bird.color as Any)
|
print(bird.color as Any)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
```
|
```
|
||||||
- Important: Never use `try?` or `try!` on a `cancel()` call. Always use `try`. Using `try?` will swallow the cancellation and the transaction will proceed to commit as normal. Using `try!` will crash the app as `cancel()` will *always* throw an error.
|
- Important: Never use `try?` or `try!` on a `cancel()` call. Always use `try`. Using `try?` will swallow the cancellation and the transaction will proceed to commit as normal. Using `try!` will crash the app as `cancel()` will *always* throw an error.
|
||||||
*/
|
*/
|
||||||
public func cancel() throws -> Never {
|
public func cancel() throws(CoreStoreError) -> Never {
|
||||||
|
|
||||||
throw CoreStoreError.userCancelled
|
throw CoreStoreError.userCancelled
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
||||||
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
||||||
*/
|
*/
|
||||||
public override func create<O>(_ into: Into<O>) -> O {
|
public override func create<O>(
|
||||||
|
_ into: Into<O>
|
||||||
|
) -> O {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -82,7 +84,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited
|
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
||||||
*/
|
*/
|
||||||
public override func edit<O: DynamicObject>(_ object: O?) -> O? {
|
public override func edit<O: DynamicObject>(
|
||||||
|
_ object: O?
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -99,7 +103,10 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
||||||
*/
|
*/
|
||||||
public override func edit<O>(_ into: Into<O>, _ objectID: NSManagedObjectID) -> O? {
|
public override func edit<O>(
|
||||||
|
_ into: Into<O>,
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -114,7 +121,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
- parameter objectIDs: the `NSManagedObjectID`s of the objects to delete
|
- parameter objectIDs: the `NSManagedObjectID`s of the objects to delete
|
||||||
*/
|
*/
|
||||||
public override func delete<S: Sequence>(objectIDs: S) where S.Iterator.Element: NSManagedObjectID {
|
public override func delete<S: Sequence>(
|
||||||
|
objectIDs: S
|
||||||
|
) where S.Iterator.Element: NSManagedObjectID {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -130,7 +139,10 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter object: the `ObjectRepresentation` representing an `NSManagedObject` or `CoreStoreObject` to be deleted
|
- parameter object: the `ObjectRepresentation` representing an `NSManagedObject` or `CoreStoreObject` to be deleted
|
||||||
- parameter objects: other `ObjectRepresentation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
- parameter objects: other `ObjectRepresentation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
||||||
*/
|
*/
|
||||||
public override func delete<O: ObjectRepresentation>(_ object: O?, _ objects: O?...) {
|
public override func delete<O: ObjectRepresentation>(
|
||||||
|
_ object: O?,
|
||||||
|
_ objects: O?...
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -145,7 +157,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
- parameter objects: the `ObjectRepresenation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
- parameter objects: the `ObjectRepresenation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
||||||
*/
|
*/
|
||||||
public override func delete<S: Sequence>(_ objects: S) where S.Iterator.Element: ObjectRepresentation {
|
public override func delete<S: Sequence>(
|
||||||
|
_ objects: S
|
||||||
|
) where S.Iterator.Element: ObjectRepresentation {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -173,7 +187,12 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func autoCommit(_ completion: @escaping (_ hasChanges: Bool, _ error: CoreStoreError?) -> Void) {
|
internal func autoCommit(
|
||||||
|
_ completion: @escaping (
|
||||||
|
_ hasChanges: Bool,
|
||||||
|
_ error: CoreStoreError?
|
||||||
|
) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.isCommitted = true
|
self.isCommitted = true
|
||||||
let group = DispatchGroup()
|
let group = DispatchGroup()
|
||||||
|
|||||||
@@ -41,14 +41,15 @@ extension BaseDataTransaction {
|
|||||||
*/
|
*/
|
||||||
public func importObject<O: ImportableObject>(
|
public func importObject<O: ImportableObject>(
|
||||||
_ into: Into<O>,
|
_ into: Into<O>,
|
||||||
source: O.ImportSource) throws -> O? {
|
source: O.ImportSource
|
||||||
|
) throws(any Swift.Error) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue."
|
"Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
return try autoreleasepool {
|
return try Internals.autoreleasepool {
|
||||||
|
|
||||||
let entityType = into.entityClass
|
let entityType = into.entityClass
|
||||||
guard entityType.shouldInsert(from: source, in: self) else {
|
guard entityType.shouldInsert(from: source, in: self) else {
|
||||||
@@ -71,14 +72,15 @@ extension BaseDataTransaction {
|
|||||||
*/
|
*/
|
||||||
public func importObject<O: ImportableObject>(
|
public func importObject<O: ImportableObject>(
|
||||||
_ object: O,
|
_ object: O,
|
||||||
source: O.ImportSource) throws {
|
source: O.ImportSource
|
||||||
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to import an object of type \(Internals.typeName(object)) outside the transaction's designated queue."
|
"Attempted to import an object of type \(Internals.typeName(object)) outside the transaction's designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
try autoreleasepool {
|
try Internals.autoreleasepool {
|
||||||
|
|
||||||
let entityType = object.runtimeType()
|
let entityType = object.runtimeType()
|
||||||
guard entityType.shouldInsert(from: source, in: self) else {
|
guard entityType.shouldInsert(from: source, in: self) else {
|
||||||
@@ -99,14 +101,15 @@ extension BaseDataTransaction {
|
|||||||
*/
|
*/
|
||||||
public func importObjects<O: ImportableObject, S: Sequence>(
|
public func importObjects<O: ImportableObject, S: Sequence>(
|
||||||
_ into: Into<O>,
|
_ into: Into<O>,
|
||||||
sourceArray: S) throws -> [O] where S.Iterator.Element == O.ImportSource {
|
sourceArray: S
|
||||||
|
) throws(any Swift.Error) -> [O] where S.Iterator.Element == O.ImportSource {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue."
|
"Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
return try autoreleasepool {
|
return try Internals.autoreleasepool {
|
||||||
|
|
||||||
return try sourceArray.compactMap { (source) -> O? in
|
return try sourceArray.compactMap { (source) -> O? in
|
||||||
|
|
||||||
@@ -135,14 +138,15 @@ extension BaseDataTransaction {
|
|||||||
*/
|
*/
|
||||||
public func importUniqueObject<O: ImportableUniqueObject>(
|
public func importUniqueObject<O: ImportableUniqueObject>(
|
||||||
_ into: Into<O>,
|
_ into: Into<O>,
|
||||||
source: O.ImportSource) throws -> O? {
|
source: O.ImportSource
|
||||||
|
) throws(any Swift.Error) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue."
|
"Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
return try autoreleasepool {
|
return try Internals.autoreleasepool {
|
||||||
|
|
||||||
let entityType = into.entityClass
|
let entityType = into.entityClass
|
||||||
let uniqueIDKeyPath = entityType.uniqueIDKeyPath
|
let uniqueIDKeyPath = entityType.uniqueIDKeyPath
|
||||||
@@ -188,18 +192,21 @@ extension BaseDataTransaction {
|
|||||||
public func importUniqueObjects<O: ImportableUniqueObject, S: Sequence>(
|
public func importUniqueObjects<O: ImportableUniqueObject, S: Sequence>(
|
||||||
_ into: Into<O>,
|
_ into: Into<O>,
|
||||||
sourceArray: S,
|
sourceArray: S,
|
||||||
preProcess: @escaping (_ mapping: [O.UniqueIDType: O.ImportSource]) throws -> [O.UniqueIDType: O.ImportSource] = { $0 }) throws -> [O] where S.Iterator.Element == O.ImportSource {
|
preProcess: @escaping (
|
||||||
|
_ mapping: [O.UniqueIDType: O.ImportSource]
|
||||||
|
) throws(any Swift.Error) -> [O.UniqueIDType: O.ImportSource] = { $0 }
|
||||||
|
) throws(any Swift.Error) -> [O] where S.Iterator.Element == O.ImportSource {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue."
|
"Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
return try autoreleasepool {
|
return try Internals.autoreleasepool {
|
||||||
|
|
||||||
let entityType = into.entityClass
|
let entityType = into.entityClass
|
||||||
var importSourceByID = Dictionary<O.UniqueIDType, O.ImportSource>()
|
var importSourceByID = Dictionary<O.UniqueIDType, O.ImportSource>()
|
||||||
let sortedIDs = try autoreleasepool {
|
let sortedIDs = try Internals.autoreleasepool {
|
||||||
|
|
||||||
return try sourceArray.compactMap { (source) -> O.UniqueIDType? in
|
return try sourceArray.compactMap { (source) -> O.UniqueIDType? in
|
||||||
|
|
||||||
@@ -212,7 +219,7 @@ extension BaseDataTransaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
importSourceByID = try autoreleasepool { try preProcess(importSourceByID) }
|
importSourceByID = try Internals.autoreleasepool { try preProcess(importSourceByID) }
|
||||||
|
|
||||||
var existingObjectsByID = Dictionary<O.UniqueIDType, O>()
|
var existingObjectsByID = Dictionary<O.UniqueIDType, O>()
|
||||||
try self
|
try self
|
||||||
@@ -228,7 +235,7 @@ extension BaseDataTransaction {
|
|||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
try autoreleasepool {
|
try Internals.autoreleasepool {
|
||||||
|
|
||||||
if let object = existingObjectsByID[objectID]
|
if let object = existingObjectsByID[objectID]
|
||||||
?? self.context.insertedObjects
|
?? self.context.insertedObjects
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s deleted
|
- returns: the number of `DynamicObject`s deleted
|
||||||
*/
|
*/
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func deleteAll<O>(_ from: From<O>, _ deleteClauses: DeleteClause...) throws -> Int {
|
public func deleteAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ deleteClauses: DeleteClause...
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -56,7 +59,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s deleted
|
- returns: the number of `DynamicObject`s deleted
|
||||||
*/
|
*/
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func deleteAll<O>(_ from: From<O>, _ deleteClauses: [DeleteClause]) throws -> Int {
|
public func deleteAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ deleteClauses: [DeleteClause]
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -74,14 +80,18 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s deleted
|
- returns: the number of `DynamicObject`s deleted
|
||||||
*/
|
*/
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func deleteAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
public func deleteAll<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to delete from a \(Internals.typeName(self)) outside its designated queue."
|
"Attempted to delete from a \(Internals.typeName(self)) outside its designated queue."
|
||||||
)
|
)
|
||||||
|
return try self.context.deleteAll(
|
||||||
return try self.context.deleteAll(clauseChain.from, clauseChain.fetchClauses)
|
clauseChain.from,
|
||||||
|
clauseChain.fetchClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,7 +103,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter object: a reference to the object created/fetched outside the transaction
|
- parameter object: a reference to the object created/fetched outside the transaction
|
||||||
- returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found.
|
- returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found.
|
||||||
*/
|
*/
|
||||||
public func fetchExisting<O: DynamicObject>(_ object: O) -> O? {
|
public func fetchExisting<O: DynamicObject>(
|
||||||
|
_ object: O
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
return self.context.fetchExisting(object)
|
return self.context.fetchExisting(object)
|
||||||
}
|
}
|
||||||
@@ -104,7 +116,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object
|
- parameter objectID: the `NSManagedObjectID` for the object
|
||||||
- returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found.
|
- returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found.
|
||||||
*/
|
*/
|
||||||
public func fetchExisting<O: DynamicObject>(_ objectID: NSManagedObjectID) -> O? {
|
public func fetchExisting<O: DynamicObject>(
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
return self.context.fetchExisting(objectID)
|
return self.context.fetchExisting(objectID)
|
||||||
}
|
}
|
||||||
@@ -115,7 +129,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter objects: an array of `DynamicObject`s created/fetched outside the transaction
|
- parameter objects: an array of `DynamicObject`s created/fetched outside the transaction
|
||||||
- returns: the `DynamicObject` array for objects that exists in the transaction
|
- returns: the `DynamicObject` array for objects that exists in the transaction
|
||||||
*/
|
*/
|
||||||
public func fetchExisting<O: DynamicObject, S: Sequence>(_ objects: S) -> [O] where S.Iterator.Element == O {
|
public func fetchExisting<O: DynamicObject, S: Sequence>(
|
||||||
|
_ objects: S
|
||||||
|
) -> [O] where S.Iterator.Element == O {
|
||||||
|
|
||||||
return self.context.fetchExisting(objects)
|
return self.context.fetchExisting(objects)
|
||||||
}
|
}
|
||||||
@@ -126,7 +142,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
||||||
- returns: the `DynamicObject` array for objects that exists in the transaction
|
- returns: the `DynamicObject` array for objects that exists in the transaction
|
||||||
*/
|
*/
|
||||||
public func fetchExisting<O: DynamicObject, S: Sequence>(_ objectIDs: S) -> [O] where S.Iterator.Element == NSManagedObjectID {
|
public func fetchExisting<O: DynamicObject, S: Sequence>(
|
||||||
|
_ objectIDs: S
|
||||||
|
) -> [O] where S.Iterator.Element == NSManagedObjectID {
|
||||||
|
|
||||||
return self.context.fetchExisting(objectIDs)
|
return self.context.fetchExisting(objectIDs)
|
||||||
}
|
}
|
||||||
@@ -139,7 +157,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> O? {
|
public func fetchOne<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -156,7 +177,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> O? {
|
public func fetchOne<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -178,7 +202,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType? {
|
public func fetchOne<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> B.ObjectType? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -195,7 +221,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [O] {
|
public func fetchAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> [O] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -212,7 +241,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [O] {
|
public func fetchAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> [O] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -234,7 +266,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType] {
|
public func fetchAll<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [B.ObjectType] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -251,7 +285,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> Int {
|
public func fetchCount<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -268,7 +305,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> Int {
|
public func fetchCount<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -290,7 +330,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
public func fetchCount<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -307,7 +349,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? {
|
public func fetchObjectID<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -324,7 +369,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? {
|
public func fetchObjectID<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -346,7 +394,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> NSManagedObjectID? {
|
public func fetchObjectID<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -363,7 +413,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -380,7 +433,10 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -402,7 +458,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -425,7 +483,11 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: QueryClause...) throws -> U? {
|
public func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, U>,
|
||||||
|
_ queryClauses: QueryClause...
|
||||||
|
) throws(CoreStoreError) -> U? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -445,7 +507,11 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: [QueryClause]) throws -> U? {
|
public func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, U>,
|
||||||
|
_ queryClauses: [QueryClause]
|
||||||
|
) throws(CoreStoreError) -> U? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -469,13 +535,19 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found.
|
- returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType {
|
public func queryValue<B: QueryChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> B.ResultType? where B.ResultType: QueryableAttributeType {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to query from a \(Internals.typeName(self)) outside its designated queue."
|
"Attempted to query from a \(Internals.typeName(self)) outside its designated queue."
|
||||||
)
|
)
|
||||||
return try self.context.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
return try self.context.queryValue(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.select,
|
||||||
|
clauseChain.queryClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -489,7 +561,11 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: QueryClause...) throws -> [[String: Any]] {
|
public func queryAttributes<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, NSDictionary>,
|
||||||
|
_ queryClauses: QueryClause...
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -509,7 +585,11 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: [QueryClause]) throws -> [[String: Any]] {
|
public func queryAttributes<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, NSDictionary>,
|
||||||
|
_ queryClauses: [QueryClause]
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -542,13 +622,19 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
|
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary {
|
public func queryAttributes<B: QueryChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] where B.ResultType == NSDictionary {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to query from a \(Internals.typeName(self)) outside its designated queue."
|
"Attempted to query from a \(Internals.typeName(self)) outside its designated queue."
|
||||||
)
|
)
|
||||||
return try self.context.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
return try self.context.queryAttributes(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.select,
|
||||||
|
clauseChain.queryClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter object: the `NSManagedObject` or `CoreStoreObject` type to be edited
|
- parameter object: the `NSManagedObject` or `CoreStoreObject` type to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
||||||
*/
|
*/
|
||||||
public func edit<O: DynamicObject>(_ object: O?) -> O? {
|
public func edit<O: DynamicObject>(
|
||||||
|
_ object: O?
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -141,7 +143,10 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
||||||
*/
|
*/
|
||||||
public func edit<O>(_ into: Into<O>, _ objectID: NSManagedObjectID) -> O? {
|
public func edit<O>(
|
||||||
|
_ into: Into<O>,
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -160,7 +165,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
|
|
||||||
- parameter objectIDs: the `NSManagedObjectID`s of the objects to delete
|
- parameter objectIDs: the `NSManagedObjectID`s of the objects to delete
|
||||||
*/
|
*/
|
||||||
public func delete<S: Sequence>(objectIDs: S) where S.Iterator.Element: NSManagedObjectID {
|
public func delete<S: Sequence>(
|
||||||
|
objectIDs: S
|
||||||
|
) where S.Iterator.Element: NSManagedObjectID {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -179,7 +186,10 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter object: the `ObjectRepresentation` representing an `NSManagedObject` or `CoreStoreObject` to be deleted
|
- parameter object: the `ObjectRepresentation` representing an `NSManagedObject` or `CoreStoreObject` to be deleted
|
||||||
- parameter objects: other `ObjectRepresentation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
- parameter objects: other `ObjectRepresentation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
||||||
*/
|
*/
|
||||||
public func delete<O: ObjectRepresentation>(_ object: O?, _ objects: O?...) {
|
public func delete<O: ObjectRepresentation>(
|
||||||
|
_ object: O?,
|
||||||
|
_ objects: O?...
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -193,7 +203,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
|
|
||||||
- parameter objects: the `ObjectRepresenation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
- parameter objects: the `ObjectRepresenation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
||||||
*/
|
*/
|
||||||
public func delete<S: Sequence>(_ objects: S) where S.Iterator.Element: ObjectRepresentation {
|
public func delete<S: Sequence>(
|
||||||
|
_ objects: S
|
||||||
|
) where S.Iterator.Element: ObjectRepresentation {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -227,7 +239,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter object: the `DynamicObject` instance
|
- parameter object: the `DynamicObject` instance
|
||||||
- returns: `true` if the object has any property values changed.
|
- returns: `true` if the object has any property values changed.
|
||||||
*/
|
*/
|
||||||
public func objectHasPersistentChangedValues<O: DynamicObject>(_ object: O) -> Bool {
|
public func objectHasPersistentChangedValues<O: DynamicObject>(
|
||||||
|
_ object: O
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -246,7 +260,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter entity: the `DynamicObject` subclass to filter
|
- parameter entity: the `DynamicObject` subclass to filter
|
||||||
- returns: a `Set` of pending `DynamicObject`s of the specified type that were inserted to the transaction.
|
- returns: a `Set` of pending `DynamicObject`s of the specified type that were inserted to the transaction.
|
||||||
*/
|
*/
|
||||||
public func insertedObjects<O: DynamicObject>(_ entity: O.Type) -> Set<O> {
|
public func insertedObjects<O: DynamicObject>(
|
||||||
|
_ entity: O.Type
|
||||||
|
) -> Set<O> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -283,7 +299,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter entity: the `DynamicObject` subclass to filter
|
- parameter entity: the `DynamicObject` subclass to filter
|
||||||
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction.
|
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction.
|
||||||
*/
|
*/
|
||||||
public func insertedObjectIDs<O: DynamicObject>(_ entity: O.Type) -> Set<NSManagedObjectID> {
|
public func insertedObjectIDs<O: DynamicObject>(
|
||||||
|
_ entity: O.Type
|
||||||
|
) -> Set<NSManagedObjectID> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -302,7 +320,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter entity: the `DynamicObject` subclass to filter
|
- parameter entity: the `DynamicObject` subclass to filter
|
||||||
- returns: a `Set` of pending `DynamicObject`s of the specified type that were updated in the transaction.
|
- returns: a `Set` of pending `DynamicObject`s of the specified type that were updated in the transaction.
|
||||||
*/
|
*/
|
||||||
public func updatedObjects<O: DynamicObject>(_ entity: O.Type) -> Set<O> {
|
public func updatedObjects<O: DynamicObject>(
|
||||||
|
_ entity: O.Type
|
||||||
|
) -> Set<O> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -339,7 +359,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter entity: the `DynamicObject` subclass to filter
|
- parameter entity: the `DynamicObject` subclass to filter
|
||||||
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction.
|
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction.
|
||||||
*/
|
*/
|
||||||
public func updatedObjectIDs<O: DynamicObject>(_ entity: O.Type) -> Set<NSManagedObjectID> {
|
public func updatedObjectIDs<O: DynamicObject>(
|
||||||
|
_ entity: O.Type
|
||||||
|
) -> Set<NSManagedObjectID> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -358,7 +380,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter entity: the `DynamicObject` subclass to filter
|
- parameter entity: the `DynamicObject` subclass to filter
|
||||||
- returns: a `Set` of pending `DynamicObject`s of the specified type that were deleted from the transaction.
|
- returns: a `Set` of pending `DynamicObject`s of the specified type that were deleted from the transaction.
|
||||||
*/
|
*/
|
||||||
public func deletedObjects<O: DynamicObject>(_ entity: O.Type) -> Set<O> {
|
public func deletedObjects<O: DynamicObject>(
|
||||||
|
_ entity: O.Type
|
||||||
|
) -> Set<O> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
@@ -396,7 +420,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
- parameter entity: the `DynamicObject` subclass to filter
|
- parameter entity: the `DynamicObject` subclass to filter
|
||||||
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
|
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
|
||||||
*/
|
*/
|
||||||
public func deletedObjectIDs<O: DynamicObject>(_ entity: O.Type) -> Set<NSManagedObjectID> {
|
public func deletedObjectIDs<O: DynamicObject>(
|
||||||
|
_ entity: O.Type
|
||||||
|
) -> Set<NSManagedObjectID> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
|
|||||||
@@ -1073,12 +1073,20 @@ private func formattedDebugDescription(_ any: Any) -> String {
|
|||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createFormattedString(_ firstLine: String, _ lastLine: String, _ info: (key: String, value: Any)...) -> String {
|
private func createFormattedString(
|
||||||
|
_ firstLine: String,
|
||||||
|
_ lastLine: String,
|
||||||
|
_ info: (key: String, value: Any)...
|
||||||
|
) -> String {
|
||||||
|
|
||||||
return createFormattedString(firstLine, lastLine, info)
|
return createFormattedString(firstLine, lastLine, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createFormattedString(_ firstLine: String, _ lastLine: String, _ info: [(key: String, value: Any)]) -> String {
|
private func createFormattedString(
|
||||||
|
_ firstLine: String,
|
||||||
|
_ lastLine: String,
|
||||||
|
_ info: [(key: String, value: Any)]
|
||||||
|
) -> String {
|
||||||
|
|
||||||
var string = firstLine
|
var string = firstLine
|
||||||
for (key, value) in info {
|
for (key, value) in info {
|
||||||
@@ -1102,7 +1110,10 @@ extension String {
|
|||||||
self = self.replacingOccurrences(of: "\n", with: "\n\(String.indention(level))")
|
self = self.replacingOccurrences(of: "\n", with: "\n\(String.indention(level))")
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate mutating func appendDumpInfo(_ key: String, _ value: Any) {
|
fileprivate mutating func appendDumpInfo(
|
||||||
|
_ key: String,
|
||||||
|
_ value: Any
|
||||||
|
) {
|
||||||
|
|
||||||
self.append("\n.\(key) = \(formattedValue(value));")
|
self.append("\n.\(key) = \(formattedValue(value));")
|
||||||
}
|
}
|
||||||
@@ -1189,6 +1200,7 @@ extension NSAttributeDescription: CoreStoreDebugStringConvertible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension NSAttributeType: @retroactive CustomDebugStringConvertible {}
|
||||||
extension NSAttributeType: CoreStoreDebugStringConvertible {
|
extension NSAttributeType: CoreStoreDebugStringConvertible {
|
||||||
|
|
||||||
public var debugDescription: String {
|
public var debugDescription: String {
|
||||||
@@ -1235,6 +1247,7 @@ extension Bundle: CoreStoreDebugStringConvertible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension NSDeleteRule: @retroactive CustomDebugStringConvertible {}
|
||||||
extension NSDeleteRule: CoreStoreDebugStringConvertible {
|
extension NSDeleteRule: CoreStoreDebugStringConvertible {
|
||||||
|
|
||||||
public var debugDescription: String {
|
public var debugDescription: String {
|
||||||
@@ -1399,6 +1412,7 @@ extension Optional: CoreStoreDebugStringConvertible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Result: @retroactive CustomDebugStringConvertible {}
|
||||||
extension Result: CoreStoreDebugStringConvertible {
|
extension Result: CoreStoreDebugStringConvertible {
|
||||||
|
|
||||||
public var debugDescription: String {
|
public var debugDescription: String {
|
||||||
@@ -1425,6 +1439,7 @@ extension Result: CoreStoreDebugStringConvertible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Selector: @retroactive CustomDebugStringConvertible {}
|
||||||
extension Selector: CoreStoreDebugStringConvertible {
|
extension Selector: CoreStoreDebugStringConvertible {
|
||||||
|
|
||||||
public var debugDescription: String {
|
public var debugDescription: String {
|
||||||
|
|||||||
@@ -33,7 +33,13 @@ extension Internals {
|
|||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
internal static func log(_ level: LogLevel, message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) {
|
internal static func log(
|
||||||
|
_ level: LogLevel,
|
||||||
|
message: String,
|
||||||
|
fileName: StaticString = #file,
|
||||||
|
lineNumber: Int = #line,
|
||||||
|
functionName: StaticString = #function
|
||||||
|
) {
|
||||||
|
|
||||||
CoreStoreDefaults.logger.log(
|
CoreStoreDefaults.logger.log(
|
||||||
level: level,
|
level: level,
|
||||||
@@ -45,7 +51,13 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
internal static func log(_ error: CoreStoreError, _ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) {
|
internal static func log(
|
||||||
|
_ error: CoreStoreError,
|
||||||
|
_ message: String,
|
||||||
|
fileName: StaticString = #file,
|
||||||
|
lineNumber: Int = #line,
|
||||||
|
functionName: StaticString = #function
|
||||||
|
) {
|
||||||
|
|
||||||
CoreStoreDefaults.logger.log(
|
CoreStoreDefaults.logger.log(
|
||||||
error: error,
|
error: error,
|
||||||
@@ -57,7 +69,13 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
internal static func assert( _ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) {
|
internal static func assert(
|
||||||
|
_ condition: @autoclosure () -> Bool,
|
||||||
|
_ message: @autoclosure () -> String,
|
||||||
|
fileName: StaticString = #file,
|
||||||
|
lineNumber: Int = #line,
|
||||||
|
functionName: StaticString = #function
|
||||||
|
) {
|
||||||
|
|
||||||
CoreStoreDefaults.logger.assert(
|
CoreStoreDefaults.logger.assert(
|
||||||
condition(),
|
condition(),
|
||||||
@@ -69,7 +87,12 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
internal static func abort(_ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) -> Never {
|
internal static func abort(
|
||||||
|
_ message: String,
|
||||||
|
fileName: StaticString = #file,
|
||||||
|
lineNumber: Int = #line,
|
||||||
|
functionName: StaticString = #function
|
||||||
|
) -> Never {
|
||||||
|
|
||||||
CoreStoreDefaults.logger.abort(
|
CoreStoreDefaults.logger.abort(
|
||||||
message,
|
message,
|
||||||
|
|||||||
@@ -56,7 +56,13 @@ public protocol CoreStoreLogger {
|
|||||||
- parameter lineNumber: the source line number
|
- parameter lineNumber: the source line number
|
||||||
- parameter functionName: the source function name
|
- parameter functionName: the source function name
|
||||||
*/
|
*/
|
||||||
func log(level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString)
|
func log(
|
||||||
|
level: LogLevel,
|
||||||
|
message: String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Handles errors sent by the `CoreStore` framework.
|
Handles errors sent by the `CoreStore` framework.
|
||||||
@@ -67,7 +73,13 @@ public protocol CoreStoreLogger {
|
|||||||
- parameter lineNumber: the source line number
|
- parameter lineNumber: the source line number
|
||||||
- parameter functionName: the source function name
|
- parameter functionName: the source function name
|
||||||
*/
|
*/
|
||||||
func log(error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString)
|
func log(
|
||||||
|
error: CoreStoreError,
|
||||||
|
message: String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Handles assertions made throughout the `CoreStore` framework.
|
Handles assertions made throughout the `CoreStore` framework.
|
||||||
@@ -78,7 +90,13 @@ public protocol CoreStoreLogger {
|
|||||||
- parameter lineNumber: the source line number
|
- parameter lineNumber: the source line number
|
||||||
- parameter functionName: the source function name
|
- parameter functionName: the source function name
|
||||||
*/
|
*/
|
||||||
func assert(_ condition: @autoclosure () -> Bool, message: @autoclosure () -> String, fileName: StaticString, lineNumber: Int, functionName: StaticString)
|
func assert(
|
||||||
|
_ condition: @autoclosure () -> Bool,
|
||||||
|
message: @autoclosure () -> String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Handles fatal errors made throughout the `CoreStore` framework. The app wil terminate after this method is called.
|
Handles fatal errors made throughout the `CoreStore` framework. The app wil terminate after this method is called.
|
||||||
@@ -89,12 +107,22 @@ public protocol CoreStoreLogger {
|
|||||||
- parameter lineNumber: the source line number
|
- parameter lineNumber: the source line number
|
||||||
- parameter functionName: the source function name
|
- parameter functionName: the source function name
|
||||||
*/
|
*/
|
||||||
func abort(_ message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString)
|
func abort(
|
||||||
|
_ message: String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension CoreStoreLogger {
|
extension CoreStoreLogger {
|
||||||
|
|
||||||
public func abort(_ message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
public func abort(
|
||||||
|
_ message: String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
) {
|
||||||
|
|
||||||
Swift.fatalError(message, file: fileName, line: UInt(lineNumber))
|
Swift.fatalError(message, file: fileName, line: UInt(lineNumber))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,17 @@ import Foundation
|
|||||||
import CoreData
|
import CoreData
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - DynamicObject where Self: CoreStoreObject
|
||||||
|
|
||||||
extension DynamicObject where Self: CoreStoreObject {
|
extension DynamicObject where Self: CoreStoreObject {
|
||||||
|
|
||||||
public func observe<O, V>(_ keyPath: KeyPath<Self, FieldContainer<O>.Stored<V>>, options: NSKeyValueObservingOptions = [], changeHandler: @escaping (Self, CoreStoreObjectValueDiff<V>) -> Void) -> CoreStoreObjectKeyValueObservation {
|
// MARK: Public
|
||||||
|
|
||||||
|
public func observe<O, V>(
|
||||||
|
_ keyPath: KeyPath<Self, FieldContainer<O>.Stored<V>>,
|
||||||
|
options: NSKeyValueObservingOptions = [],
|
||||||
|
changeHandler: @escaping (Self, CoreStoreObjectValueDiff<V>) -> Void
|
||||||
|
) -> CoreStoreObjectKeyValueObservation {
|
||||||
|
|
||||||
let result = _CoreStoreObjectKeyValueObservation(
|
let result = _CoreStoreObjectKeyValueObservation(
|
||||||
object: self.rawObject!,
|
object: self.rawObject!,
|
||||||
@@ -186,7 +194,12 @@ public final class CoreStoreObjectObjectDiff<D: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: FilePrivate
|
// MARK: FilePrivate
|
||||||
|
|
||||||
fileprivate init(kind: NSKeyValueChange, newNativeValue: CoreStoreManagedObject?, oldNativeValue: CoreStoreManagedObject?, isPrior: Bool) {
|
fileprivate init(
|
||||||
|
kind: NSKeyValueChange,
|
||||||
|
newNativeValue: CoreStoreManagedObject?,
|
||||||
|
oldNativeValue: CoreStoreManagedObject?,
|
||||||
|
isPrior: Bool
|
||||||
|
) {
|
||||||
|
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self.newNativeValue = newNativeValue
|
self.newNativeValue = newNativeValue
|
||||||
@@ -232,7 +245,12 @@ public final class CoreStoreObjectUnorderedDiff<D: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: FilePrivate
|
// MARK: FilePrivate
|
||||||
|
|
||||||
fileprivate init(kind: NSKeyValueChange, newNativeValue: NSOrderedSet?, oldNativeValue: NSOrderedSet?, isPrior: Bool) {
|
fileprivate init(
|
||||||
|
kind: NSKeyValueChange,
|
||||||
|
newNativeValue: NSOrderedSet?,
|
||||||
|
oldNativeValue: NSOrderedSet?,
|
||||||
|
isPrior: Bool
|
||||||
|
) {
|
||||||
|
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self.newNativeValue = newNativeValue ?? []
|
self.newNativeValue = newNativeValue ?? []
|
||||||
@@ -283,7 +301,13 @@ public final class CoreStoreObjectOrderedDiff<D: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: FilePrivate
|
// MARK: FilePrivate
|
||||||
|
|
||||||
fileprivate init(kind: NSKeyValueChange, newNativeValue: NSArray?, oldNativeValue: NSArray?, indexes: IndexSet, isPrior: Bool) {
|
fileprivate init(
|
||||||
|
kind: NSKeyValueChange,
|
||||||
|
newNativeValue: NSArray?,
|
||||||
|
oldNativeValue: NSArray?,
|
||||||
|
indexes: IndexSet,
|
||||||
|
isPrior: Bool
|
||||||
|
) {
|
||||||
|
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self.newNativeValue = newNativeValue ?? []
|
self.newNativeValue = newNativeValue ?? []
|
||||||
@@ -362,7 +386,18 @@ fileprivate final class _CoreStoreObjectKeyValueObservation: NSObject, CoreStore
|
|||||||
// MARK: FilePrivate
|
// MARK: FilePrivate
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
fileprivate init(object: CoreStoreManagedObject, keyPath: KeyPathString, callback: @escaping (_ object: CoreStoreManagedObject, _ kind: NSKeyValueChange, _ newValue: Any?, _ oldValue: Any?, _ indexes: IndexSet?, _ isPrior: Bool) -> Void) {
|
fileprivate init(
|
||||||
|
object: CoreStoreManagedObject,
|
||||||
|
keyPath: KeyPathString,
|
||||||
|
callback: @escaping (
|
||||||
|
_ object: CoreStoreManagedObject,
|
||||||
|
_ kind: NSKeyValueChange,
|
||||||
|
_ newValue: Any?,
|
||||||
|
_ oldValue: Any?,
|
||||||
|
_ indexes: IndexSet?,
|
||||||
|
_ isPrior: Bool
|
||||||
|
) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
let _ = _CoreStoreObjectKeyValueObservation.swizzler
|
let _ = _CoreStoreObjectKeyValueObservation.swizzler
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
@@ -373,12 +408,19 @@ fileprivate final class _CoreStoreObjectKeyValueObservation: NSObject, CoreStore
|
|||||||
@nonobjc
|
@nonobjc
|
||||||
fileprivate func start(_ options: NSKeyValueObservingOptions) {
|
fileprivate func start(_ options: NSKeyValueObservingOptions) {
|
||||||
|
|
||||||
self.object?.addObserver(self, forKeyPath: self.keyPath, options: options, context: nil)
|
self.object?
|
||||||
|
.addObserver(
|
||||||
|
self,
|
||||||
|
forKeyPath: self.keyPath,
|
||||||
|
options: options,
|
||||||
|
context: nil
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
|
||||||
self.object?.removeObserver(self, forKeyPath: self.keyPath, context: nil)
|
self.object?
|
||||||
|
.removeObserver(self, forKeyPath: self.keyPath, context: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -387,7 +429,8 @@ fileprivate final class _CoreStoreObjectKeyValueObservation: NSObject, CoreStore
|
|||||||
@nonobjc
|
@nonobjc
|
||||||
public func invalidate() {
|
public func invalidate() {
|
||||||
|
|
||||||
self.object?.removeObserver(self, forKeyPath: self.keyPath, context: nil)
|
self.object?
|
||||||
|
.removeObserver(self, forKeyPath: self.keyPath, context: nil)
|
||||||
self.object = nil
|
self.object = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,11 +444,17 @@ fileprivate final class _CoreStoreObjectKeyValueObservation: NSObject, CoreStore
|
|||||||
let bridgeClass: AnyClass = _CoreStoreObjectKeyValueObservation.self
|
let bridgeClass: AnyClass = _CoreStoreObjectKeyValueObservation.self
|
||||||
let rootObserveImpl = class_getInstanceMethod(
|
let rootObserveImpl = class_getInstanceMethod(
|
||||||
bridgeClass,
|
bridgeClass,
|
||||||
#selector(_CoreStoreObjectKeyValueObservation.observeValue(forKeyPath:of:change:context:))
|
#selector(
|
||||||
|
_CoreStoreObjectKeyValueObservation
|
||||||
|
.observeValue(forKeyPath:of:change:context:)
|
||||||
|
)
|
||||||
)!
|
)!
|
||||||
let swapObserveImpl = class_getInstanceMethod(
|
let swapObserveImpl = class_getInstanceMethod(
|
||||||
bridgeClass,
|
bridgeClass,
|
||||||
#selector(_CoreStoreObjectKeyValueObservation._cs_swizzle_me_observeValue(forKeyPath:of:change:context:))
|
#selector(
|
||||||
|
_CoreStoreObjectKeyValueObservation
|
||||||
|
._cs_swizzle_me_observeValue(forKeyPath:of:change:context:)
|
||||||
|
)
|
||||||
)!
|
)!
|
||||||
method_exchangeImplementations(rootObserveImpl, swapObserveImpl)
|
method_exchangeImplementations(rootObserveImpl, swapObserveImpl)
|
||||||
return nil
|
return nil
|
||||||
@@ -415,13 +464,25 @@ fileprivate final class _CoreStoreObjectKeyValueObservation: NSObject, CoreStore
|
|||||||
private weak var object: CoreStoreManagedObject?
|
private weak var object: CoreStoreManagedObject?
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
private let callback: (_ object: CoreStoreManagedObject, _ kind: NSKeyValueChange, _ newValue: Any?, _ oldValue: Any?, _ indexes: IndexSet?, _ isPrior: Bool) -> Void
|
private let callback: (
|
||||||
|
_ object: CoreStoreManagedObject,
|
||||||
|
_ kind: NSKeyValueChange,
|
||||||
|
_ newValue: Any?,
|
||||||
|
_ oldValue: Any?,
|
||||||
|
_ indexes: IndexSet?,
|
||||||
|
_ isPrior: Bool
|
||||||
|
) -> Void
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
private let keyPath: KeyPathString
|
private let keyPath: KeyPathString
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
private dynamic func _cs_swizzle_me_observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSString: Any]?, context: UnsafeMutableRawPointer?) {
|
private dynamic func _cs_swizzle_me_observeValue(
|
||||||
|
forKeyPath keyPath: String?,
|
||||||
|
of object: Any?,
|
||||||
|
change: [NSString: Any]?,
|
||||||
|
context: UnsafeMutableRawPointer?
|
||||||
|
) {
|
||||||
|
|
||||||
guard
|
guard
|
||||||
let object = object as? CoreStoreManagedObject,
|
let object = object as? CoreStoreManagedObject,
|
||||||
|
|||||||
@@ -36,9 +36,15 @@ extension FieldContainer.Stored {
|
|||||||
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname == "John" }))
|
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname == "John" }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func == (_ attribute: Self, _ value: V) -> Where<O> {
|
public static func == (
|
||||||
|
_ attribute: Self,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where(attribute.keyPath, isEqualTo: value)
|
return Where(
|
||||||
|
attribute.keyPath,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,9 +53,15 @@ extension FieldContainer.Stored {
|
|||||||
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname != "John" }))
|
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname != "John" }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func != (_ attribute: Self, _ value: V) -> Where<O> {
|
public static func != (
|
||||||
|
_ attribute: Self,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where(attribute.keyPath, isEqualTo: value)
|
return !Where(
|
||||||
|
attribute.keyPath,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,9 +70,16 @@ extension FieldContainer.Stored {
|
|||||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age < 20 }))
|
let person = dataStack.fetchOne(From<Person>().where({ $0.age < 20 }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func < (_ attribute: Self, _ value: V) -> Where<O> {
|
public static func < (
|
||||||
|
_ attribute: Self,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where("%K < %@", attribute.keyPath, value.cs_toFieldStoredNativeType() as Any)
|
return Where(
|
||||||
|
"%K < %@",
|
||||||
|
attribute.keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as Any
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,9 +88,16 @@ extension FieldContainer.Stored {
|
|||||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age > 20 }))
|
let person = dataStack.fetchOne(From<Person>().where({ $0.age > 20 }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func > (_ attribute: Self, _ value: V) -> Where<O> {
|
public static func > (
|
||||||
|
_ attribute: Self,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where("%K > %@", attribute.keyPath, value.cs_toFieldStoredNativeType() as Any)
|
return Where(
|
||||||
|
"%K > %@",
|
||||||
|
attribute.keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as Any
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,9 +106,16 @@ extension FieldContainer.Stored {
|
|||||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age <= 20 }))
|
let person = dataStack.fetchOne(From<Person>().where({ $0.age <= 20 }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func <= (_ attribute: Self, _ value: V) -> Where<O> {
|
public static func <= (
|
||||||
|
_ attribute: Self,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where("%K <= %@", attribute.keyPath, value.cs_toFieldStoredNativeType() as Any)
|
return Where(
|
||||||
|
"%K <= %@",
|
||||||
|
attribute.keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as Any
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,9 +124,16 @@ extension FieldContainer.Stored {
|
|||||||
let person = dataStack.fetchOne(From<Person>().where({ $0.age >= 20 }))
|
let person = dataStack.fetchOne(From<Person>().where({ $0.age >= 20 }))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public static func >= (_ attribute: Self, _ value: V) -> Where<O> {
|
public static func >= (
|
||||||
|
_ attribute: Self,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where("%K >= %@", attribute.keyPath, value.cs_toFieldStoredNativeType() as Any)
|
return Where(
|
||||||
|
"%K >= %@",
|
||||||
|
attribute.keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as Any
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,9 +142,15 @@ extension FieldContainer.Stored {
|
|||||||
let dog = dataStack.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: Self) -> Where<O> where S.Iterator.Element == V {
|
public static func ~= <S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ attribute: Self
|
||||||
|
) -> Where<O> where S.Iterator.Element == V {
|
||||||
|
|
||||||
return Where(attribute.keyPath, isMemberOf: sequence)
|
return Where(
|
||||||
|
attribute.keyPath,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,10 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
|
|||||||
|
|
||||||
internal class func metaProperties(includeSuperclasses: Bool) -> [PropertyProtocol] {
|
internal class func metaProperties(includeSuperclasses: Bool) -> [PropertyProtocol] {
|
||||||
|
|
||||||
func keyPaths(_ allKeyPaths: inout [PropertyProtocol], for dynamicType: CoreStoreObject.Type) {
|
func keyPaths(
|
||||||
|
_ allKeyPaths: inout [PropertyProtocol],
|
||||||
|
for dynamicType: CoreStoreObject.Type
|
||||||
|
) {
|
||||||
|
|
||||||
allKeyPaths.append(contentsOf: dynamicType.meta.propertyProtocolsByName())
|
allKeyPaths.append(contentsOf: dynamicType.meta.propertyProtocolsByName())
|
||||||
guard
|
guard
|
||||||
@@ -151,7 +154,10 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private func containsLegacyAttributes(mirror: Mirror, object: CoreStoreObject) -> Bool {
|
private func containsLegacyAttributes(
|
||||||
|
mirror: Mirror,
|
||||||
|
object: CoreStoreObject
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
if let superclassMirror = mirror.superclassMirror,
|
if let superclassMirror = mirror.superclassMirror,
|
||||||
self.containsLegacyAttributes(mirror: superclassMirror, object: object) {
|
self.containsLegacyAttributes(mirror: superclassMirror, object: object) {
|
||||||
@@ -175,7 +181,10 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private func registerReceiver(mirror: Mirror, object: CoreStoreObject) {
|
private func registerReceiver(
|
||||||
|
mirror: Mirror,
|
||||||
|
object: CoreStoreObject
|
||||||
|
) {
|
||||||
|
|
||||||
if let superclassMirror = mirror.superclassMirror {
|
if let superclassMirror = mirror.superclassMirror {
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,11 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
- parameter entities: an array of `Entity<T>` pertaining to all `CoreStoreObject` subclasses to be added to the schema version.
|
- parameter entities: an array of `Entity<T>` pertaining to all `CoreStoreObject` subclasses to be added to the schema version.
|
||||||
- parameter versionLock: an optional list of `VersionLock` hashes for each entity name in the `entities` array. If any `DynamicEntity` doesn't match its version lock hash, an assertion will be raised.
|
- parameter versionLock: an optional list of `VersionLock` hashes for each entity name in the `entities` array. If any `DynamicEntity` doesn't match its version lock hash, an assertion will be raised.
|
||||||
*/
|
*/
|
||||||
public convenience init(modelVersion: ModelVersion, entities: [DynamicEntity], versionLock: VersionLock? = nil) {
|
public convenience init(
|
||||||
|
modelVersion: ModelVersion,
|
||||||
|
entities: [DynamicEntity],
|
||||||
|
versionLock: VersionLock? = nil
|
||||||
|
) {
|
||||||
|
|
||||||
var entityConfigurations: [DynamicEntity: Set<String>] = [:]
|
var entityConfigurations: [DynamicEntity: Set<String>] = [:]
|
||||||
for entity in entities {
|
for entity in entities {
|
||||||
@@ -138,7 +142,11 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
- parameter entityConfigurations: a dictionary with `Entity<T>` pertaining to all `CoreStoreObject` subclasses and the corresponding list of "Configurations" they should be added to. To add an entity only to the default configuration, assign an empty set to its configurations list. Note that regardless of the set configurations, all entities will be added to the default configuration.
|
- parameter entityConfigurations: a dictionary with `Entity<T>` pertaining to all `CoreStoreObject` subclasses and the corresponding list of "Configurations" they should be added to. To add an entity only to the default configuration, assign an empty set to its configurations list. Note that regardless of the set configurations, all entities will be added to the default configuration.
|
||||||
- parameter versionLock: an optional list of `VersionLock` hashes for each entity name in the `entities` array. If any `DynamicEntity` doesn't match its version lock hash, an assertion will be raised.
|
- parameter versionLock: an optional list of `VersionLock` hashes for each entity name in the `entities` array. If any `DynamicEntity` doesn't match its version lock hash, an assertion will be raised.
|
||||||
*/
|
*/
|
||||||
public required init(modelVersion: ModelVersion, entityConfigurations: [DynamicEntity: Set<String>], versionLock: VersionLock? = nil) {
|
public required init(
|
||||||
|
modelVersion: ModelVersion,
|
||||||
|
entityConfigurations: [DynamicEntity: Set<String>],
|
||||||
|
versionLock: VersionLock? = nil
|
||||||
|
) {
|
||||||
|
|
||||||
var actualEntitiesByConfiguration: [String: Set<DynamicEntity>] = [:]
|
var actualEntitiesByConfiguration: [String: Set<DynamicEntity>] = [:]
|
||||||
for (entity, configurations) in entityConfigurations {
|
for (entity, configurations) in entityConfigurations {
|
||||||
@@ -305,7 +313,10 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func firstPassCreateEntityDescription(from entity: DynamicEntity, in modelVersion: ModelVersion) -> (
|
private static func firstPassCreateEntityDescription(
|
||||||
|
from entity: DynamicEntity,
|
||||||
|
in modelVersion: ModelVersion
|
||||||
|
) -> (
|
||||||
entity: NSEntityDescription,
|
entity: NSEntityDescription,
|
||||||
customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter],
|
customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter],
|
||||||
customInitializerByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomInitializer],
|
customInitializerByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomInitializer],
|
||||||
@@ -323,7 +334,10 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
var customInitialValuesByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomInitializer] = [:]
|
var customInitialValuesByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomInitializer] = [:]
|
||||||
var customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter] = [:]
|
var customGetterSetterByKeyPaths: [KeyPathString: CoreStoreManagedObject.CustomGetterSetter] = [:]
|
||||||
var fieldCoders: [KeyPathString: Internals.AnyFieldCoder] = [:]
|
var fieldCoders: [KeyPathString: Internals.AnyFieldCoder] = [:]
|
||||||
func createProperties(for type: CoreStoreObject.Type) -> [NSPropertyDescription] {
|
|
||||||
|
func createProperties(
|
||||||
|
for type: CoreStoreObject.Type
|
||||||
|
) -> [NSPropertyDescription] {
|
||||||
|
|
||||||
var propertyDescriptions: [NSPropertyDescription] = []
|
var propertyDescriptions: [NSPropertyDescription] = []
|
||||||
for property in type.metaProperties(includeSuperclasses: false) {
|
for property in type.metaProperties(includeSuperclasses: false) {
|
||||||
@@ -425,14 +439,19 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func secondPassConnectRelationshipAttributes(for entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription]) {
|
private static func secondPassConnectRelationshipAttributes(
|
||||||
|
for entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription]
|
||||||
|
) {
|
||||||
|
|
||||||
var relationshipsByNameByEntity: [DynamicEntity: [String: NSRelationshipDescription]] = [:]
|
var relationshipsByNameByEntity: [DynamicEntity: [String: NSRelationshipDescription]] = [:]
|
||||||
for (entity, entityDescription) in entityDescriptionsByEntity {
|
for (entity, entityDescription) in entityDescriptionsByEntity {
|
||||||
|
|
||||||
relationshipsByNameByEntity[entity] = entityDescription.relationshipsByName
|
relationshipsByNameByEntity[entity] = entityDescription.relationshipsByName
|
||||||
}
|
}
|
||||||
func findEntity(for type: CoreStoreObject.Type) -> DynamicEntity {
|
|
||||||
|
func findEntity(
|
||||||
|
for type: CoreStoreObject.Type
|
||||||
|
) -> DynamicEntity {
|
||||||
|
|
||||||
var matchedEntities: Set<DynamicEntity> = []
|
var matchedEntities: Set<DynamicEntity> = []
|
||||||
for (entity, _) in entityDescriptionsByEntity where entity.type == type {
|
for (entity, _) in entityDescriptionsByEntity where entity.type == type {
|
||||||
@@ -457,7 +476,10 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func findInverseRelationshipMatching(destinationEntity: DynamicEntity, destinationKeyPath: String) -> NSRelationshipDescription {
|
func findInverseRelationshipMatching(
|
||||||
|
destinationEntity: DynamicEntity,
|
||||||
|
destinationKeyPath: String
|
||||||
|
) -> NSRelationshipDescription {
|
||||||
|
|
||||||
for case (destinationKeyPath, let relationshipDescription) in relationshipsByNameByEntity[destinationEntity]! {
|
for case (destinationKeyPath, let relationshipDescription) in relationshipsByNameByEntity[destinationEntity]! {
|
||||||
|
|
||||||
@@ -537,9 +559,14 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func thirdPassConnectInheritanceTreeAndIndexes(for entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription]) {
|
private static func thirdPassConnectInheritanceTreeAndIndexes(
|
||||||
|
for entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription]
|
||||||
|
) {
|
||||||
|
|
||||||
func connectBaseEntity(mirror: Mirror, entityDescription: NSEntityDescription) {
|
func connectBaseEntity(
|
||||||
|
mirror: Mirror,
|
||||||
|
entityDescription: NSEntityDescription
|
||||||
|
) {
|
||||||
|
|
||||||
guard let superclassMirror = mirror.superclassMirror,
|
guard let superclassMirror = mirror.superclassMirror,
|
||||||
let superType = superclassMirror.subjectType as? CoreStoreObject.Type,
|
let superType = superclassMirror.subjectType as? CoreStoreObject.Type,
|
||||||
|
|||||||
@@ -51,7 +51,11 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
- parameter destinationVersion: the destination model version for the mapping
|
- parameter destinationVersion: the destination model version for the mapping
|
||||||
- parameter entityMappings: a list of `CustomMapping`s. Mappings of entities with no `CustomMapping` provided will be automatically calculated if possible. Any conflicts or ambiguity will raise an assertion.
|
- parameter entityMappings: a list of `CustomMapping`s. Mappings of entities with no `CustomMapping` provided will be automatically calculated if possible. Any conflicts or ambiguity will raise an assertion.
|
||||||
*/
|
*/
|
||||||
public required init(from sourceVersion: ModelVersion, to destinationVersion: ModelVersion, entityMappings: Set<CustomMapping> = []) {
|
public required init(
|
||||||
|
from sourceVersion: ModelVersion,
|
||||||
|
to destinationVersion: ModelVersion,
|
||||||
|
entityMappings: Set<CustomMapping> = []
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Internals.with {
|
Internals.with {
|
||||||
@@ -101,12 +105,18 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
- parameter sourceObject: a proxy object representing the source entity. The properties can be accessed via keyPath.
|
- parameter sourceObject: a proxy object representing the source entity. The properties can be accessed via keyPath.
|
||||||
- parameter createDestinationObject: the closure to create the object for the destination entity. The `CustomMapping.inferredTransformation` method can be used directly as the `transformer` if the changes can be inferred (i.e. lightweight). The object is created lazily and executing the closure multiple times will return the same instance. The destination object's properties can be accessed and updated via keyPath.
|
- parameter createDestinationObject: the closure to create the object for the destination entity. The `CustomMapping.inferredTransformation` method can be used directly as the `transformer` if the changes can be inferred (i.e. lightweight). The object is created lazily and executing the closure multiple times will return the same instance. The destination object's properties can be accessed and updated via keyPath.
|
||||||
*/
|
*/
|
||||||
public typealias Transformer = (_ sourceObject: UnsafeSourceObject, _ createDestinationObject: () -> UnsafeDestinationObject) throws -> Void
|
public typealias Transformer = (
|
||||||
|
_ sourceObject: UnsafeSourceObject,
|
||||||
|
_ createDestinationObject: () -> UnsafeDestinationObject
|
||||||
|
) throws(any Swift.Error) -> Void
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `CustomMapping.inferredTransformation` method can be used directly as the `transformer` if the changes can be inferred (i.e. lightweight).
|
The `CustomMapping.inferredTransformation` method can be used directly as the `transformer` if the changes can be inferred (i.e. lightweight).
|
||||||
*/
|
*/
|
||||||
public static func inferredTransformation(_ sourceObject: UnsafeSourceObject, _ createDestinationObject: () -> UnsafeDestinationObject) throws -> Void {
|
public static func inferredTransformation(
|
||||||
|
_ sourceObject: UnsafeSourceObject,
|
||||||
|
_ createDestinationObject: () -> UnsafeDestinationObject
|
||||||
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
let destinationObject = createDestinationObject()
|
let destinationObject = createDestinationObject()
|
||||||
destinationObject.enumerateAttributes { (attribute, sourceAttribute) in
|
destinationObject.enumerateAttributes { (attribute, sourceAttribute) in
|
||||||
@@ -343,7 +353,14 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
|
|
||||||
// MARK: SchemaMappingProvider
|
// MARK: SchemaMappingProvider
|
||||||
|
|
||||||
public func cs_createMappingModel(from sourceSchema: DynamicSchema, to destinationSchema: DynamicSchema, storage: LocalStorage) throws -> (mappingModel: NSMappingModel, migrationType: MigrationType) {
|
public func cs_createMappingModel(
|
||||||
|
from sourceSchema: DynamicSchema,
|
||||||
|
to destinationSchema: DynamicSchema,
|
||||||
|
storage: LocalStorage
|
||||||
|
) throws(CoreStoreError) -> (
|
||||||
|
mappingModel: NSMappingModel,
|
||||||
|
migrationType: MigrationType
|
||||||
|
) {
|
||||||
|
|
||||||
let sourceModel = sourceSchema.rawModel()
|
let sourceModel = sourceSchema.rawModel()
|
||||||
let destinationModel = destinationSchema.rawModel()
|
let destinationModel = destinationSchema.rawModel()
|
||||||
@@ -535,7 +552,11 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
|
|
||||||
// MARK: NSEntityMigrationPolicy
|
// MARK: NSEntityMigrationPolicy
|
||||||
|
|
||||||
override func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws {
|
override func createDestinationInstances(
|
||||||
|
forSource sInstance: NSManagedObject,
|
||||||
|
in mapping: NSEntityMapping,
|
||||||
|
manager: NSMigrationManager
|
||||||
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
let userInfo = mapping.userInfo!
|
let userInfo = mapping.userInfo!
|
||||||
let transformer = userInfo[CustomEntityMigrationPolicy.UserInfoKey.transformer]! as! CustomMapping.Transformer
|
let transformer = userInfo[CustomEntityMigrationPolicy.UserInfoKey.transformer]! as! CustomMapping.Transformer
|
||||||
@@ -563,7 +584,11 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func createRelationships(forDestination dInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws {
|
override func createRelationships(
|
||||||
|
forDestination dInstance: NSManagedObject,
|
||||||
|
in mapping: NSEntityMapping,
|
||||||
|
manager: NSMigrationManager
|
||||||
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
try super.createRelationships(forDestination: dInstance, in: mapping, manager: manager)
|
try super.createRelationships(forDestination: dInstance, in: mapping, manager: manager)
|
||||||
}
|
}
|
||||||
@@ -583,7 +608,15 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
|
|
||||||
private let entityMappings: Set<CustomMapping>
|
private let entityMappings: Set<CustomMapping>
|
||||||
|
|
||||||
private func resolveEntityMappings(sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel) -> (delete: Set<CustomMapping>, insert: Set<CustomMapping>, copy: Set<CustomMapping>, transform: Set<CustomMapping>) {
|
private func resolveEntityMappings(
|
||||||
|
sourceModel: NSManagedObjectModel,
|
||||||
|
destinationModel: NSManagedObjectModel
|
||||||
|
) -> (
|
||||||
|
delete: Set<CustomMapping>,
|
||||||
|
insert: Set<CustomMapping>,
|
||||||
|
copy: Set<CustomMapping>,
|
||||||
|
transform: Set<CustomMapping>
|
||||||
|
) {
|
||||||
|
|
||||||
var deleteMappings: Set<CustomMapping> = []
|
var deleteMappings: Set<CustomMapping> = []
|
||||||
var insertMappings: Set<CustomMapping> = []
|
var insertMappings: Set<CustomMapping> = []
|
||||||
|
|||||||
@@ -85,13 +85,16 @@ extension DataStack.AsyncNamespace {
|
|||||||
*/
|
*/
|
||||||
public func addStorage<T: StorageInterface>(
|
public func addStorage<T: StorageInterface>(
|
||||||
_ storage: T
|
_ storage: T
|
||||||
) async throws -> T {
|
) async throws(any Swift.Error) -> T {
|
||||||
|
|
||||||
return try await withCheckedThrowingContinuation { continuation in
|
return try await Internals.withCheckedThrowingContinuation { continuation in
|
||||||
|
|
||||||
self.base.addStorage(
|
self.base.addStorage(
|
||||||
storage,
|
storage,
|
||||||
completion: continuation.resume(with:)
|
completion: {
|
||||||
|
|
||||||
|
continuation.resume(with: $0)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +118,7 @@ extension DataStack.AsyncNamespace {
|
|||||||
*/
|
*/
|
||||||
public func addStorage<T>(
|
public func addStorage<T>(
|
||||||
_ storage: T
|
_ storage: T
|
||||||
) -> AsyncThrowingStream<MigrationProgress<T>, Swift.Error> {
|
) -> AsyncThrowingStream<MigrationProgress<T>, any Swift.Error> {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
bufferingPolicy: .unbounded,
|
bufferingPolicy: .unbounded,
|
||||||
@@ -178,9 +181,9 @@ extension DataStack.AsyncNamespace {
|
|||||||
public func importObject<O: DynamicObject & ImportableObject>(
|
public func importObject<O: DynamicObject & ImportableObject>(
|
||||||
_ into: Into<O>,
|
_ into: Into<O>,
|
||||||
source: O.ImportSource
|
source: O.ImportSource
|
||||||
) async throws -> O? {
|
) async throws(any Swift.Error) -> O? {
|
||||||
|
|
||||||
return try await withCheckedThrowingContinuation { continuation in
|
return try await Internals.withCheckedThrowingContinuation { continuation in
|
||||||
|
|
||||||
self.base.perform(
|
self.base.perform(
|
||||||
asynchronous: { (transaction) -> O? in
|
asynchronous: { (transaction) -> O? in
|
||||||
@@ -217,9 +220,9 @@ extension DataStack.AsyncNamespace {
|
|||||||
public func importObject<O: DynamicObject & ImportableObject>(
|
public func importObject<O: DynamicObject & ImportableObject>(
|
||||||
_ object: O,
|
_ object: O,
|
||||||
source: O.ImportSource
|
source: O.ImportSource
|
||||||
) async throws -> O? {
|
) async throws(any Swift.Error) -> O? {
|
||||||
|
|
||||||
return try await withCheckedThrowingContinuation { continuation in
|
return try await Internals.withCheckedThrowingContinuation { continuation in
|
||||||
|
|
||||||
self.base.perform(
|
self.base.perform(
|
||||||
asynchronous: { (transaction) -> O? in
|
asynchronous: { (transaction) -> O? in
|
||||||
@@ -261,9 +264,9 @@ extension DataStack.AsyncNamespace {
|
|||||||
public func importUniqueObject<O: DynamicObject & ImportableUniqueObject>(
|
public func importUniqueObject<O: DynamicObject & ImportableUniqueObject>(
|
||||||
_ into: Into<O>,
|
_ into: Into<O>,
|
||||||
source: O.ImportSource
|
source: O.ImportSource
|
||||||
) async throws -> O? {
|
) async throws(any Swift.Error) -> O? {
|
||||||
|
|
||||||
return try await withCheckedThrowingContinuation { continuation in
|
return try await Internals.withCheckedThrowingContinuation { continuation in
|
||||||
|
|
||||||
self.base.perform(
|
self.base.perform(
|
||||||
asynchronous: { (transaction) -> O? in
|
asynchronous: { (transaction) -> O? in
|
||||||
@@ -306,11 +309,13 @@ extension DataStack.AsyncNamespace {
|
|||||||
public func importUniqueObjects<O: DynamicObject & ImportableUniqueObject, S: Sequence>(
|
public func importUniqueObjects<O: DynamicObject & ImportableUniqueObject, S: Sequence>(
|
||||||
_ into: Into<O>,
|
_ into: Into<O>,
|
||||||
sourceArray: S,
|
sourceArray: S,
|
||||||
preProcess: @escaping @Sendable (_ mapping: [O.UniqueIDType: O.ImportSource]) throws -> [O.UniqueIDType: O.ImportSource] = { $0 }
|
preProcess: @escaping @Sendable (
|
||||||
) async throws -> [O]
|
_ mapping: [O.UniqueIDType: O.ImportSource]
|
||||||
|
) throws(any Swift.Error) -> [O.UniqueIDType: O.ImportSource] = { $0 }
|
||||||
|
) async throws(any Swift.Error) -> [O]
|
||||||
where S.Iterator.Element == O.ImportSource {
|
where S.Iterator.Element == O.ImportSource {
|
||||||
|
|
||||||
return try await withCheckedThrowingContinuation { continuation in
|
return try await Internals.withCheckedThrowingContinuation { continuation in
|
||||||
|
|
||||||
self.base.perform(
|
self.base.perform(
|
||||||
asynchronous: { (transaction) -> [O] in
|
asynchronous: { (transaction) -> [O] in
|
||||||
@@ -353,14 +358,17 @@ extension DataStack.AsyncNamespace {
|
|||||||
- throws: A `CoreStoreError` value indicating the failure reason
|
- throws: A `CoreStoreError` value indicating the failure reason
|
||||||
*/
|
*/
|
||||||
public func perform<Output>(
|
public func perform<Output>(
|
||||||
_ asynchronous: @escaping @Sendable (AsynchronousDataTransaction) throws -> Output
|
_ asynchronous: @escaping @Sendable (AsynchronousDataTransaction) throws(any Swift.Error) -> Output
|
||||||
) async throws -> Output {
|
) async throws(any Swift.Error) -> Output {
|
||||||
|
|
||||||
return try await withCheckedThrowingContinuation { continuation in
|
return try await Internals.withCheckedThrowingContinuation { continuation in
|
||||||
|
|
||||||
self.base.perform(
|
self.base.perform(
|
||||||
asynchronous: asynchronous,
|
asynchronous: asynchronous,
|
||||||
completion: continuation.resume(with:)
|
completion: {
|
||||||
|
|
||||||
|
continuation.resume(with: $0)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ extension DataStack {
|
|||||||
- parameter object: the `DynamicObject` to observe changes from
|
- parameter object: the `DynamicObject` to observe changes from
|
||||||
- returns: an `ObjectPublisher` that broadcasts changes to `object`
|
- returns: an `ObjectPublisher` that broadcasts changes to `object`
|
||||||
*/
|
*/
|
||||||
public func publishObject<O: DynamicObject>(_ object: O) -> ObjectPublisher<O> {
|
public func publishObject<O: DynamicObject>(
|
||||||
|
_ object: O
|
||||||
|
) -> ObjectPublisher<O> {
|
||||||
|
|
||||||
return self.publishObject(object.cs_id())
|
return self.publishObject(object.cs_id())
|
||||||
}
|
}
|
||||||
@@ -50,7 +52,9 @@ extension DataStack {
|
|||||||
- parameter objectID: the `ObjectID` of the object to observe changes from
|
- parameter objectID: the `ObjectID` of the object to observe changes from
|
||||||
- returns: an `ObjectPublisher` that broadcasts changes to `object`
|
- returns: an `ObjectPublisher` that broadcasts changes to `object`
|
||||||
*/
|
*/
|
||||||
public func publishObject<O: DynamicObject>(_ objectID: O.ObjectID) -> ObjectPublisher<O> {
|
public func publishObject<O: DynamicObject>(
|
||||||
|
_ objectID: O.ObjectID
|
||||||
|
) -> ObjectPublisher<O> {
|
||||||
|
|
||||||
let context = self.unsafeContext()
|
let context = self.unsafeContext()
|
||||||
return context.objectPublisher(objectID: objectID)
|
return context.objectPublisher(objectID: objectID)
|
||||||
@@ -74,7 +78,9 @@ extension DataStack {
|
|||||||
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
||||||
*/
|
*/
|
||||||
public func publishList<B: FetchChainableBuilderType>(_ clauseChain: B) -> ListPublisher<B.ObjectType> {
|
public func publishList<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) -> ListPublisher<B.ObjectType> {
|
||||||
|
|
||||||
return self.publishList(
|
return self.publishList(
|
||||||
clauseChain.from,
|
clauseChain.from,
|
||||||
@@ -101,7 +107,9 @@ extension DataStack {
|
|||||||
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
||||||
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
||||||
*/
|
*/
|
||||||
public func publishList<B: SectionMonitorBuilderType>(_ clauseChain: B) -> ListPublisher<B.ObjectType> {
|
public func publishList<B: SectionMonitorBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) -> ListPublisher<B.ObjectType> {
|
||||||
|
|
||||||
return self.publishList(
|
return self.publishList(
|
||||||
clauseChain.from,
|
clauseChain.from,
|
||||||
@@ -117,7 +125,10 @@ extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
||||||
*/
|
*/
|
||||||
public func publishList<O>(_ from: From<O>, _ fetchClauses: FetchClause...) -> ListPublisher<O> {
|
public func publishList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> ListPublisher<O> {
|
||||||
|
|
||||||
return self.publishList(from, fetchClauses)
|
return self.publishList(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -129,7 +140,10 @@ extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
||||||
*/
|
*/
|
||||||
public func publishList<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) -> ListPublisher<O> {
|
public func publishList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> ListPublisher<O> {
|
||||||
|
|
||||||
return ListPublisher(
|
return ListPublisher(
|
||||||
dataStack: self,
|
dataStack: self,
|
||||||
@@ -155,7 +169,11 @@ extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
||||||
*/
|
*/
|
||||||
public func publishList<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) -> ListPublisher<O> {
|
public func publishList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> ListPublisher<O> {
|
||||||
|
|
||||||
return self.publishList(
|
return self.publishList(
|
||||||
from,
|
from,
|
||||||
@@ -172,7 +190,11 @@ extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
- returns: a `ListPublisher` that broadcasts changes to the fetched results
|
||||||
*/
|
*/
|
||||||
public func publishList<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) -> ListPublisher<O> {
|
public func publishList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> ListPublisher<O> {
|
||||||
|
|
||||||
return ListPublisher(
|
return ListPublisher(
|
||||||
dataStack: self,
|
dataStack: self,
|
||||||
|
|||||||
@@ -47,7 +47,10 @@ extension DataStack {
|
|||||||
- parameter storage: the storage
|
- parameter storage: the storage
|
||||||
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
|
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
|
||||||
*/
|
*/
|
||||||
public func addStorage<T>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) {
|
public func addStorage<T>(
|
||||||
|
_ storage: T,
|
||||||
|
completion: @escaping (SetupResult<T>) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.coordinator.performAsynchronously {
|
self.coordinator.performAsynchronously {
|
||||||
|
|
||||||
@@ -105,7 +108,10 @@ extension DataStack {
|
|||||||
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` 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.
|
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` 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: a `Progress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured.
|
- returns: a `Progress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured.
|
||||||
*/
|
*/
|
||||||
public func addStorage<T: LocalStorage>(_ storage: T, completion: @escaping (SetupResult<T>) -> Void) -> Progress? {
|
public func addStorage<T: LocalStorage>(
|
||||||
|
_ storage: T,
|
||||||
|
completion: @escaping (SetupResult<T>) -> Void
|
||||||
|
) -> Progress? {
|
||||||
|
|
||||||
let fileURL = storage.fileURL
|
let fileURL = storage.fileURL
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
@@ -256,7 +262,10 @@ extension DataStack {
|
|||||||
- throws: a `CoreStoreError` value indicating the failure
|
- throws: a `CoreStoreError` value indicating the failure
|
||||||
- returns: a `Progress` instance if a migration has started, or `nil` is no migrations are required
|
- returns: a `Progress` instance if a migration has started, or `nil` is no migrations are required
|
||||||
*/
|
*/
|
||||||
public func upgradeStorageIfNeeded<T: LocalStorage>(_ storage: T, completion: @escaping (MigrationResult) -> Void) throws -> Progress? {
|
public func upgradeStorageIfNeeded<T: LocalStorage>(
|
||||||
|
_ storage: T,
|
||||||
|
completion: @escaping (MigrationResult) -> Void
|
||||||
|
) throws(CoreStoreError) -> Progress? {
|
||||||
|
|
||||||
return try self.coordinator.performSynchronously {
|
return try self.coordinator.performSynchronously {
|
||||||
|
|
||||||
@@ -298,7 +307,9 @@ extension DataStack {
|
|||||||
- throws: a `CoreStoreError` value indicating the failure
|
- throws: a `CoreStoreError` value indicating the failure
|
||||||
- returns: a `MigrationType` array indicating the migration steps required for the store, or an empty array if the file does not exist yet. Otherwise, an error is thrown if either inspection of the store failed, or if no mapping model was found/inferred.
|
- returns: a `MigrationType` array indicating the migration steps required for the store, or an empty array if the file does not exist yet. Otherwise, an error is thrown if either inspection of the store failed, or if no mapping model was found/inferred.
|
||||||
*/
|
*/
|
||||||
public func requiredMigrationsForStorage<T: LocalStorage>(_ storage: T) throws -> [MigrationType] {
|
public func requiredMigrationsForStorage<T: LocalStorage>(
|
||||||
|
_ storage: T
|
||||||
|
) throws(CoreStoreError) -> [MigrationType] {
|
||||||
|
|
||||||
return try self.coordinator.performSynchronously {
|
return try self.coordinator.performSynchronously {
|
||||||
|
|
||||||
@@ -362,7 +373,11 @@ extension DataStack {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private func upgradeStorageIfNeeded<T: LocalStorage>(_ storage: T, metadata: [String: Any], completion: @escaping (MigrationResult) -> Void) -> Progress? {
|
private func upgradeStorageIfNeeded<T: LocalStorage>(
|
||||||
|
_ storage: T,
|
||||||
|
metadata: [String: Any],
|
||||||
|
completion: @escaping (MigrationResult) -> Void
|
||||||
|
) -> Progress? {
|
||||||
|
|
||||||
guard let migrationSteps = self.computeMigrationFromStorage(storage, metadata: metadata) else {
|
guard let migrationSteps = self.computeMigrationFromStorage(storage, metadata: metadata) else {
|
||||||
|
|
||||||
@@ -485,7 +500,10 @@ extension DataStack {
|
|||||||
return progress
|
return progress
|
||||||
}
|
}
|
||||||
|
|
||||||
private func computeMigrationFromStorage<T: LocalStorage>(_ storage: T, metadata: [String: Any]) -> [(sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel, mappingModel: NSMappingModel, migrationType: MigrationType)]? {
|
private func computeMigrationFromStorage<T: LocalStorage>(
|
||||||
|
_ storage: T,
|
||||||
|
metadata: [String: Any]
|
||||||
|
) -> [(sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel, mappingModel: NSMappingModel, migrationType: MigrationType)]? {
|
||||||
|
|
||||||
let schemaHistory = self.schemaHistory
|
let schemaHistory = self.schemaHistory
|
||||||
if schemaHistory.rawModel.isConfiguration(withName: storage.configuration, compatibleWithStoreMetadata: metadata) {
|
if schemaHistory.rawModel.isConfiguration(withName: storage.configuration, compatibleWithStoreMetadata: metadata) {
|
||||||
@@ -545,7 +563,14 @@ extension DataStack {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private func startMigrationForStorage<T: LocalStorage>(_ storage: T, sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel, mappingModel: NSMappingModel, migrationType: MigrationType, progress: Progress) throws {
|
private func startMigrationForStorage<T: LocalStorage>(
|
||||||
|
_ storage: T,
|
||||||
|
sourceModel: NSManagedObjectModel,
|
||||||
|
destinationModel: NSManagedObjectModel,
|
||||||
|
mappingModel: NSMappingModel,
|
||||||
|
migrationType: MigrationType,
|
||||||
|
progress: Progress
|
||||||
|
) throws(CoreStoreError) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
@@ -703,7 +728,11 @@ extension DataStack {
|
|||||||
|
|
||||||
extension Array where Element == SchemaMappingProvider {
|
extension Array where Element == SchemaMappingProvider {
|
||||||
|
|
||||||
func findMapping(sourceSchema: DynamicSchema, destinationSchema: DynamicSchema, storage: LocalStorage) throws -> (mappingModel: NSMappingModel, migrationType: MigrationType) {
|
func findMapping(
|
||||||
|
sourceSchema: DynamicSchema,
|
||||||
|
destinationSchema: DynamicSchema,
|
||||||
|
storage: LocalStorage
|
||||||
|
) throws(CoreStoreError) -> (mappingModel: NSMappingModel, migrationType: MigrationType) {
|
||||||
|
|
||||||
for element in self {
|
for element in self {
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ extension DataStack {
|
|||||||
- parameter object: the `DynamicObject` to observe changes from
|
- parameter object: the `DynamicObject` to observe changes from
|
||||||
- returns: an `ObjectMonitor` that monitors changes to `object`
|
- returns: an `ObjectMonitor` that monitors changes to `object`
|
||||||
*/
|
*/
|
||||||
public func monitorObject<O: DynamicObject>(_ object: O) -> ObjectMonitor<O> {
|
public func monitorObject<O: DynamicObject>(
|
||||||
|
_ object: O
|
||||||
|
) -> ObjectMonitor<O> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -53,7 +55,10 @@ extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorList<O>(_ from: From<O>, _ fetchClauses: FetchClause...) -> ListMonitor<O> {
|
public func monitorList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> ListMonitor<O> {
|
||||||
|
|
||||||
return self.monitorList(from, fetchClauses)
|
return self.monitorList(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -65,7 +70,10 @@ extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorList<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) -> ListMonitor<O> {
|
public func monitorList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> ListMonitor<O> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -99,7 +107,9 @@ extension DataStack {
|
|||||||
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
- returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
*/
|
*/
|
||||||
public func monitorList<B: FetchChainableBuilderType>(_ clauseChain: B) -> ListMonitor<B.ObjectType> {
|
public func monitorList<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) -> ListMonitor<B.ObjectType> {
|
||||||
|
|
||||||
return self.monitorList(
|
return self.monitorList(
|
||||||
clauseChain.from,
|
clauseChain.from,
|
||||||
@@ -114,7 +124,11 @@ extension DataStack {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorList<O>(createAsynchronously: @escaping (ListMonitor<O>) -> Void, _ from: From<O>, _ fetchClauses: FetchClause...) {
|
public func monitorList<O>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<O>) -> Void,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) {
|
||||||
|
|
||||||
self.monitorList(
|
self.monitorList(
|
||||||
createAsynchronously: createAsynchronously,
|
createAsynchronously: createAsynchronously,
|
||||||
@@ -130,7 +144,11 @@ extension DataStack {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorList<O>(createAsynchronously: @escaping (ListMonitor<O>) -> Void, _ from: From<O>, _ fetchClauses: [FetchClause]) {
|
public func monitorList<O>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<O>) -> Void,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -169,7 +187,10 @@ extension DataStack {
|
|||||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
*/
|
*/
|
||||||
public func monitorList<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public func monitorList<B: FetchChainableBuilderType>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void,
|
||||||
|
_ clauseChain: B
|
||||||
|
) {
|
||||||
|
|
||||||
self.monitorList(
|
self.monitorList(
|
||||||
createAsynchronously: createAsynchronously,
|
createAsynchronously: createAsynchronously,
|
||||||
@@ -186,7 +207,11 @@ extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) -> ListMonitor<O> {
|
public func monitorSectionedList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> ListMonitor<O> {
|
||||||
|
|
||||||
return self.monitorSectionedList(
|
return self.monitorSectionedList(
|
||||||
from,
|
from,
|
||||||
@@ -203,7 +228,11 @@ extension DataStack {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) -> ListMonitor<O> {
|
public func monitorSectionedList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> ListMonitor<O> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -239,7 +268,9 @@ extension DataStack {
|
|||||||
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
||||||
- returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType`
|
- returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType`
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<B: SectionMonitorBuilderType>(_ clauseChain: B) -> ListMonitor<B.ObjectType> {
|
public func monitorSectionedList<B: SectionMonitorBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) -> ListMonitor<B.ObjectType> {
|
||||||
|
|
||||||
return self.monitorSectionedList(
|
return self.monitorSectionedList(
|
||||||
clauseChain.from,
|
clauseChain.from,
|
||||||
@@ -256,7 +287,12 @@ extension DataStack {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<O>(createAsynchronously: @escaping (ListMonitor<O>) -> Void, _ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) {
|
public func monitorSectionedList<O>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<O>) -> Void,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) {
|
||||||
|
|
||||||
self.monitorSectionedList(
|
self.monitorSectionedList(
|
||||||
createAsynchronously: createAsynchronously,
|
createAsynchronously: createAsynchronously,
|
||||||
@@ -274,7 +310,12 @@ extension DataStack {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<O>(createAsynchronously: @escaping (ListMonitor<O>) -> Void, _ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) {
|
public func monitorSectionedList<O>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<O>) -> Void,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -314,7 +355,10 @@ extension DataStack {
|
|||||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public func monitorSectionedList<B: SectionMonitorBuilderType>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void,
|
||||||
|
_ clauseChain: B
|
||||||
|
) {
|
||||||
|
|
||||||
self.monitorSectionedList(
|
self.monitorSectionedList(
|
||||||
createAsynchronously: createAsynchronously,
|
createAsynchronously: createAsynchronously,
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter object: a reference to the object created/fetched outside the `DataStack`
|
- 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.
|
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
||||||
*/
|
*/
|
||||||
public func fetchExisting<O: DynamicObject>(_ object: O) -> O? {
|
public func fetchExisting<O: DynamicObject>(
|
||||||
|
_ object: O
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
return self.mainContext.fetchExisting(object)
|
return self.mainContext.fetchExisting(object)
|
||||||
}
|
}
|
||||||
@@ -50,7 +52,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object
|
- parameter objectID: the `NSManagedObjectID` for the object
|
||||||
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
||||||
*/
|
*/
|
||||||
public func fetchExisting<O: DynamicObject>(_ objectID: NSManagedObjectID) -> O? {
|
public func fetchExisting<O: DynamicObject>(
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
return self.mainContext.fetchExisting(objectID)
|
return self.mainContext.fetchExisting(objectID)
|
||||||
}
|
}
|
||||||
@@ -61,7 +65,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack`
|
- parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack`
|
||||||
- returns: the `DynamicObject` array for objects that exists in the `DataStack`
|
- returns: the `DynamicObject` array for objects that exists in the `DataStack`
|
||||||
*/
|
*/
|
||||||
public func fetchExisting<O: DynamicObject, S: Sequence>(_ objects: S) -> [O] where S.Iterator.Element == O {
|
public func fetchExisting<O: DynamicObject, S: Sequence>(
|
||||||
|
_ objects: S
|
||||||
|
) -> [O] where S.Iterator.Element == O {
|
||||||
|
|
||||||
return self.mainContext.fetchExisting(objects)
|
return self.mainContext.fetchExisting(objects)
|
||||||
}
|
}
|
||||||
@@ -72,7 +78,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
||||||
- returns: the `DynamicObject` array for objects that exists in the `DataStack`
|
- returns: the `DynamicObject` array for objects that exists in the `DataStack`
|
||||||
*/
|
*/
|
||||||
public func fetchExisting<O: DynamicObject, S: Sequence>(_ objectIDs: S) -> [O] where S.Iterator.Element == NSManagedObjectID {
|
public func fetchExisting<O: DynamicObject, S: Sequence>(
|
||||||
|
_ objectIDs: S
|
||||||
|
) -> [O] where S.Iterator.Element == NSManagedObjectID {
|
||||||
|
|
||||||
return self.mainContext.fetchExisting(objectIDs)
|
return self.mainContext.fetchExisting(objectIDs)
|
||||||
}
|
}
|
||||||
@@ -85,7 +93,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> O? {
|
public func fetchOne<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -102,7 +113,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> O? {
|
public func fetchOne<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -124,7 +138,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType? {
|
public func fetchOne<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> B.ObjectType? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -141,7 +157,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [O] {
|
public func fetchAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> [O] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -158,7 +177,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [O] {
|
public func fetchAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> [O] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -180,7 +202,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType] {
|
public func fetchAll<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [B.ObjectType] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -197,7 +221,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> Int {
|
public func fetchCount<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -214,7 +241,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> Int {
|
public func fetchCount<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -236,7 +266,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
public func fetchCount<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -253,7 +285,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? {
|
public func fetchObjectID<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -270,7 +305,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? {
|
public func fetchObjectID<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -292,7 +330,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> NSManagedObjectID? {
|
public func fetchObjectID<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -309,7 +349,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -326,7 +369,10 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -348,7 +394,9 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -371,7 +419,11 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: QueryClause...) throws -> U? {
|
public func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, U>,
|
||||||
|
_ queryClauses: QueryClause...
|
||||||
|
) throws(CoreStoreError) -> U? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -391,7 +443,11 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: [QueryClause]) throws -> U? {
|
public func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, U>,
|
||||||
|
_ queryClauses: [QueryClause]
|
||||||
|
) throws(CoreStoreError) -> U? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -415,13 +471,19 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found.
|
- returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType {
|
public func queryValue<B: QueryChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> B.ResultType? where B.ResultType: QueryableAttributeType {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
|
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
|
||||||
)
|
)
|
||||||
return try self.mainContext.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
return try self.mainContext.queryValue(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.select,
|
||||||
|
clauseChain.queryClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -435,7 +497,11 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: QueryClause...) throws -> [[String: Any]] {
|
public func queryAttributes<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, NSDictionary>,
|
||||||
|
_ queryClauses: QueryClause...
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -455,7 +521,11 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: [QueryClause]) throws -> [[String: Any]] {
|
public func queryAttributes<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, NSDictionary>,
|
||||||
|
_ queryClauses: [QueryClause]
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
@@ -488,13 +558,19 @@ extension DataStack: FetchableSource, QueryableSource {
|
|||||||
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
|
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
public func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary {
|
public func queryAttributes<B: QueryChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] where B.ResultType == NSDictionary {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
|
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
|
||||||
)
|
)
|
||||||
return try self.mainContext.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
return try self.mainContext.queryAttributes(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.select,
|
||||||
|
clauseChain.queryClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,9 @@ extension DataStack.ReactiveNamespace {
|
|||||||
- parameter storage: the local storage
|
- parameter storage: the local storage
|
||||||
- returns: A `DataStack.AddStoragePublisher` that emits a `MigrationProgress` value with metadata for migration progress. Note that the `LocalStorage` event value 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: A `DataStack.AddStoragePublisher` that emits a `MigrationProgress` value with metadata for migration progress. Note that the `LocalStorage` event value 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.
|
||||||
*/
|
*/
|
||||||
public func addStorage<T: LocalStorage>(_ storage: T) -> DataStack.AddStoragePublisher<T> {
|
public func addStorage<T: LocalStorage>(
|
||||||
|
_ storage: T
|
||||||
|
) -> DataStack.AddStoragePublisher<T> {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
dataStack: self.base,
|
dataStack: self.base,
|
||||||
@@ -317,7 +319,9 @@ extension DataStack.ReactiveNamespace {
|
|||||||
public func importUniqueObjects<O: DynamicObject & ImportableUniqueObject, S: Sequence>(
|
public func importUniqueObjects<O: DynamicObject & ImportableUniqueObject, S: Sequence>(
|
||||||
_ into: Into<O>,
|
_ into: Into<O>,
|
||||||
sourceArray: S,
|
sourceArray: S,
|
||||||
preProcess: @escaping (_ mapping: [O.UniqueIDType: O.ImportSource]) throws -> [O.UniqueIDType: O.ImportSource] = { $0 }
|
preProcess: @escaping (
|
||||||
|
_ mapping: [O.UniqueIDType: O.ImportSource]
|
||||||
|
) throws(any Swift.Error) -> [O.UniqueIDType: O.ImportSource] = { $0 }
|
||||||
) -> Future<[O], CoreStoreError> where S.Iterator.Element == O.ImportSource {
|
) -> Future<[O], CoreStoreError> where S.Iterator.Element == O.ImportSource {
|
||||||
|
|
||||||
return .init { (promise) in
|
return .init { (promise) in
|
||||||
@@ -367,7 +371,9 @@ extension DataStack.ReactiveNamespace {
|
|||||||
- returns: A `Future` whose event value be the value returned from the `task` closure.
|
- returns: A `Future` whose event value be the value returned from the `task` closure.
|
||||||
*/
|
*/
|
||||||
public func perform<Output>(
|
public func perform<Output>(
|
||||||
_ asynchronous: @escaping (AsynchronousDataTransaction) throws -> Output
|
_ asynchronous: @escaping (
|
||||||
|
_ transaction: AsynchronousDataTransaction
|
||||||
|
) throws(any Swift.Error) -> Output
|
||||||
) -> Future<Output, CoreStoreError> {
|
) -> Future<Output, CoreStoreError> {
|
||||||
|
|
||||||
return .init { (promise) in
|
return .init { (promise) in
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ extension DataStack {
|
|||||||
- 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)`.
|
- 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 func perform<T>(
|
public func perform<T>(
|
||||||
asynchronous task: @escaping (_ transaction: AsynchronousDataTransaction) throws -> T,
|
asynchronous task: @escaping (
|
||||||
|
_ transaction: AsynchronousDataTransaction
|
||||||
|
) throws(any Swift.Error) -> T,
|
||||||
sourceIdentifier: Any? = nil,
|
sourceIdentifier: Any? = nil,
|
||||||
completion: @escaping (AsynchronousDataTransaction.Result<T>) -> Void
|
completion: @escaping (AsynchronousDataTransaction.Result<T>) -> Void
|
||||||
) {
|
) {
|
||||||
@@ -61,7 +63,9 @@ extension DataStack {
|
|||||||
- parameter failure: the closure executed if the save fails or if any errors are thrown within `task`. Cancelled `task`s will be indicated by `CoreStoreError.userCancelled`. Custom errors thrown by the user will be wrapped in `CoreStoreError.userError(error: Error)`.
|
- parameter failure: the closure executed if the save fails or if any errors are thrown within `task`. Cancelled `task`s will be indicated by `CoreStoreError.userCancelled`. Custom errors thrown by the user will be wrapped in `CoreStoreError.userError(error: Error)`.
|
||||||
*/
|
*/
|
||||||
public func perform<T>(
|
public func perform<T>(
|
||||||
asynchronous task: @escaping (_ transaction: AsynchronousDataTransaction) throws -> T,
|
asynchronous task: @escaping (
|
||||||
|
_ transaction: AsynchronousDataTransaction
|
||||||
|
) throws(any Swift.Error) -> T,
|
||||||
sourceIdentifier: Any? = nil,
|
sourceIdentifier: Any? = nil,
|
||||||
success: @escaping (T) -> Void,
|
success: @escaping (T) -> Void,
|
||||||
failure: @escaping (CoreStoreError) -> Void
|
failure: @escaping (CoreStoreError) -> Void
|
||||||
@@ -117,17 +121,19 @@ extension DataStack {
|
|||||||
- returns: the value returned from `task`
|
- returns: the value returned from `task`
|
||||||
*/
|
*/
|
||||||
public func perform<T>(
|
public func perform<T>(
|
||||||
synchronous task: ((_ transaction: SynchronousDataTransaction) throws -> T),
|
synchronous task: (
|
||||||
|
_ transaction: SynchronousDataTransaction
|
||||||
|
) throws(any Swift.Error) -> T,
|
||||||
waitForAllObservers: Bool = true,
|
waitForAllObservers: Bool = true,
|
||||||
sourceIdentifier: Any? = nil
|
sourceIdentifier: Any? = nil
|
||||||
) throws -> T {
|
) throws(CoreStoreError) -> T {
|
||||||
|
|
||||||
let transaction = SynchronousDataTransaction(
|
let transaction = SynchronousDataTransaction(
|
||||||
mainContext: self.rootSavingContext,
|
mainContext: self.rootSavingContext,
|
||||||
queue: self.childTransactionQueue,
|
queue: self.childTransactionQueue,
|
||||||
sourceIdentifier: sourceIdentifier
|
sourceIdentifier: sourceIdentifier
|
||||||
)
|
)
|
||||||
return try transaction.transactionQueue.cs_sync {
|
return try transaction.transactionQueue.cs_sync { () throws(CoreStoreError) -> T in
|
||||||
|
|
||||||
defer {
|
defer {
|
||||||
|
|
||||||
@@ -140,7 +146,7 @@ extension DataStack {
|
|||||||
}
|
}
|
||||||
catch let error as CoreStoreError {
|
catch let error as CoreStoreError {
|
||||||
|
|
||||||
throw error
|
throw error as CoreStoreError
|
||||||
}
|
}
|
||||||
catch let error {
|
catch let error {
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ extension DataStack {
|
|||||||
public typealias Output = CoreStore.MigrationProgress<Storage>
|
public typealias Output = CoreStore.MigrationProgress<Storage>
|
||||||
public typealias Failure = CoreStoreError
|
public typealias Failure = CoreStoreError
|
||||||
|
|
||||||
public func receive<S: Subscriber>(subscriber: S) where S.Input == Output, S.Failure == Failure {
|
public func receive<S: Subscriber>(
|
||||||
|
subscriber: S
|
||||||
|
) where S.Input == Output, S.Failure == Failure {
|
||||||
|
|
||||||
subscriber.receive(
|
subscriber.receive(
|
||||||
subscription: AddStorageSubscription(
|
subscription: AddStorageSubscription(
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ public final class DataStack: Equatable {
|
|||||||
- returns: the local SQLite storage added to the stack
|
- returns: the local SQLite storage added to the stack
|
||||||
*/
|
*/
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func addStorageAndWait() throws -> SQLiteStore {
|
public func addStorageAndWait() throws(CoreStoreError) -> SQLiteStore {
|
||||||
|
|
||||||
return try self.addStorageAndWait(SQLiteStore())
|
return try self.addStorageAndWait(SQLiteStore())
|
||||||
}
|
}
|
||||||
@@ -258,7 +258,7 @@ public final class DataStack: Equatable {
|
|||||||
@discardableResult
|
@discardableResult
|
||||||
public func addStorageAndWait<T: StorageInterface>(
|
public func addStorageAndWait<T: StorageInterface>(
|
||||||
_ storage: T
|
_ storage: T
|
||||||
) throws -> T {
|
) throws(CoreStoreError) -> T {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
@@ -278,12 +278,11 @@ public final class DataStack: Equatable {
|
|||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|
||||||
let storeError = CoreStoreError(error)
|
|
||||||
Internals.log(
|
Internals.log(
|
||||||
storeError,
|
error,
|
||||||
"Failed to add \(Internals.typeName(storage)) to the stack."
|
"Failed to add \(Internals.typeName(storage)) to the stack."
|
||||||
)
|
)
|
||||||
throw storeError
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +298,7 @@ public final class DataStack: Equatable {
|
|||||||
@discardableResult
|
@discardableResult
|
||||||
public func addStorageAndWait<T: LocalStorage>(
|
public func addStorageAndWait<T: LocalStorage>(
|
||||||
_ storage: T
|
_ storage: T
|
||||||
) throws -> T {
|
) throws(CoreStoreError) -> T {
|
||||||
|
|
||||||
return try self.coordinator.performSynchronously {
|
return try self.coordinator.performSynchronously {
|
||||||
|
|
||||||
@@ -539,7 +538,7 @@ public final class DataStack: Equatable {
|
|||||||
_ storage: StorageInterface,
|
_ storage: StorageInterface,
|
||||||
finalURL: URL?,
|
finalURL: URL?,
|
||||||
finalStoreOptions: [AnyHashable: Any]?
|
finalStoreOptions: [AnyHashable: Any]?
|
||||||
) throws -> NSPersistentStore {
|
) throws(any Swift.Error) -> NSPersistentStore {
|
||||||
|
|
||||||
let persistentStore = try self.coordinator.addPersistentStore(
|
let persistentStore = try self.coordinator.addPersistentStore(
|
||||||
ofType: type(of: storage).storeType,
|
ofType: type(of: storage).storeType,
|
||||||
|
|||||||
@@ -47,7 +47,13 @@ public final class DefaultLogger: CoreStoreLogger {
|
|||||||
- parameter lineNumber: the source line number
|
- parameter lineNumber: the source line number
|
||||||
- parameter functionName: the source function name
|
- parameter functionName: the source function name
|
||||||
*/
|
*/
|
||||||
public func log(level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
public func log(
|
||||||
|
level: LogLevel,
|
||||||
|
message: String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
) {
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
let icon: String
|
let icon: String
|
||||||
@@ -83,7 +89,13 @@ public final class DefaultLogger: CoreStoreLogger {
|
|||||||
- parameter lineNumber: the source line number
|
- parameter lineNumber: the source line number
|
||||||
- parameter functionName: the source function name
|
- parameter functionName: the source function name
|
||||||
*/
|
*/
|
||||||
public func log(error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
public func log(
|
||||||
|
error: CoreStoreError,
|
||||||
|
message: String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
) {
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Swift.print("⚠️ [CoreStore: Error] \((String(describing: fileName) as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ \(message)\n \(error)\n")
|
Swift.print("⚠️ [CoreStore: Error] \((String(describing: fileName) as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ \(message)\n \(error)\n")
|
||||||
@@ -99,7 +111,13 @@ public final class DefaultLogger: CoreStoreLogger {
|
|||||||
- parameter lineNumber: the source line number
|
- parameter lineNumber: the source line number
|
||||||
- parameter functionName: the source function name
|
- parameter functionName: the source function name
|
||||||
*/
|
*/
|
||||||
public func assert(_ condition: @autoclosure () -> Bool, message: @autoclosure () -> String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
public func assert(
|
||||||
|
_ condition: @autoclosure () -> Bool,
|
||||||
|
message: @autoclosure () -> String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
) {
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if condition() {
|
if condition() {
|
||||||
@@ -120,7 +138,12 @@ public final class DefaultLogger: CoreStoreLogger {
|
|||||||
- parameter lineNumber: the source line number
|
- parameter lineNumber: the source line number
|
||||||
- parameter functionName: the source function name
|
- parameter functionName: the source function name
|
||||||
*/
|
*/
|
||||||
public func abort(_ message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
public func abort(
|
||||||
|
_ message: String,
|
||||||
|
fileName: StaticString,
|
||||||
|
lineNumber: Int,
|
||||||
|
functionName: StaticString
|
||||||
|
) {
|
||||||
|
|
||||||
Swift.print("❗ [CoreStore: Fatal Error] \((String(describing: fileName) as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ \(message)\n")
|
Swift.print("❗ [CoreStore: Fatal Error] \((String(describing: fileName) as NSString).lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ \(message)\n")
|
||||||
Swift.fatalError(file: fileName, line: UInt(lineNumber))
|
Swift.fatalError(file: fileName, line: UInt(lineNumber))
|
||||||
|
|||||||
@@ -31,7 +31,10 @@ import Foundation
|
|||||||
extension DispatchQueue {
|
extension DispatchQueue {
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
internal static func serial(_ label: String, qos: DispatchQoS) -> DispatchQueue {
|
internal static func serial(
|
||||||
|
_ label: String,
|
||||||
|
qos: DispatchQoS
|
||||||
|
) -> DispatchQueue {
|
||||||
|
|
||||||
return DispatchQueue(
|
return DispatchQueue(
|
||||||
label: label,
|
label: label,
|
||||||
@@ -43,7 +46,10 @@ extension DispatchQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
internal static func concurrent(_ label: String, qos: DispatchQoS) -> DispatchQueue {
|
internal static func concurrent(
|
||||||
|
_ label: String,
|
||||||
|
qos: DispatchQoS
|
||||||
|
) -> DispatchQueue {
|
||||||
|
|
||||||
return DispatchQueue(
|
return DispatchQueue(
|
||||||
label: label,
|
label: label,
|
||||||
@@ -69,25 +75,56 @@ extension DispatchQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
internal func cs_sync<T>(_ closure: () throws -> T) rethrows -> T {
|
internal func cs_sync<T>(
|
||||||
|
_ closure: () -> T
|
||||||
|
) -> T {
|
||||||
|
|
||||||
|
return self.sync { autoreleasepool(invoking: closure) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@nonobjc @inline(__always)
|
||||||
|
internal func cs_sync<T>(
|
||||||
|
_ closure: () throws(any Swift.Error) -> T
|
||||||
|
) throws(any Swift.Error) -> T {
|
||||||
|
|
||||||
return try self.sync { try autoreleasepool(invoking: closure) }
|
return try self.sync { try autoreleasepool(invoking: closure) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
internal func cs_async(_ closure: @escaping () -> Void) {
|
internal func cs_sync<T>(
|
||||||
|
_ closure: () throws(CoreStoreError) -> T
|
||||||
|
) throws(CoreStoreError) -> T {
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
return try self.sync { try autoreleasepool(invoking: closure) }
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
|
||||||
|
throw CoreStoreError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@nonobjc @inline(__always)
|
||||||
|
internal func cs_async(
|
||||||
|
_ closure: @escaping () -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.async { autoreleasepool(invoking: closure) }
|
self.async { autoreleasepool(invoking: closure) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
internal func cs_barrierSync<T>(_ closure: () throws -> T) rethrows -> T {
|
internal func cs_barrierSync<T>(
|
||||||
|
_ closure: () throws(any Swift.Error) -> T
|
||||||
|
) rethrows -> T {
|
||||||
|
|
||||||
return try self.sync(flags: .barrier) { try autoreleasepool(invoking: closure) }
|
return try self.sync(flags: .barrier) { try autoreleasepool(invoking: closure) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
internal func cs_barrierAsync(_ closure: @escaping () -> Void) {
|
internal func cs_barrierAsync(
|
||||||
|
_ closure: @escaping () -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.async(flags: .barrier) { autoreleasepool(invoking: closure) }
|
self.async(flags: .barrier) { autoreleasepool(invoking: closure) }
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-12
@@ -42,22 +42,33 @@ public protocol DynamicObject: AnyObject {
|
|||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_forceCreate(entityDescription: NSEntityDescription, into context: NSManagedObjectContext, assignTo store: NSPersistentStore) -> Self
|
static func cs_forceCreate(
|
||||||
|
entityDescription: NSEntityDescription,
|
||||||
|
into context: NSManagedObjectContext,
|
||||||
|
assignTo store: NSPersistentStore
|
||||||
|
) -> Self
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_snapshotDictionary(id: ObjectID, context: NSManagedObjectContext) -> [String: Any]?
|
static func cs_snapshotDictionary(
|
||||||
|
id: ObjectID,
|
||||||
|
context: NSManagedObjectContext
|
||||||
|
) -> [String: Any]?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_fromRaw(object: NSManagedObject) -> Self
|
static func cs_fromRaw(
|
||||||
|
object: NSManagedObject
|
||||||
|
) -> Self
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_matches(object: NSManagedObject) -> Bool
|
static func cs_matches(
|
||||||
|
object: NSManagedObject
|
||||||
|
) -> Bool
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
@@ -88,7 +99,11 @@ extension NSManagedObject: DynamicObject {
|
|||||||
|
|
||||||
// MARK: DynamicObject
|
// MARK: DynamicObject
|
||||||
|
|
||||||
public class func cs_forceCreate(entityDescription: NSEntityDescription, into context: NSManagedObjectContext, assignTo store: NSPersistentStore) -> Self {
|
public class func cs_forceCreate(
|
||||||
|
entityDescription: NSEntityDescription,
|
||||||
|
into context: NSManagedObjectContext,
|
||||||
|
assignTo store: NSPersistentStore
|
||||||
|
) -> Self {
|
||||||
|
|
||||||
let object = self.init(entity: entityDescription, insertInto: context)
|
let object = self.init(entity: entityDescription, insertInto: context)
|
||||||
defer {
|
defer {
|
||||||
@@ -98,7 +113,10 @@ extension NSManagedObject: DynamicObject {
|
|||||||
return object
|
return object
|
||||||
}
|
}
|
||||||
|
|
||||||
public class func cs_snapshotDictionary(id: ObjectID, context: NSManagedObjectContext) -> [String: Any]? {
|
public class func cs_snapshotDictionary(
|
||||||
|
id: ObjectID,
|
||||||
|
context: NSManagedObjectContext
|
||||||
|
) -> [String: Any]? {
|
||||||
|
|
||||||
guard let object = context.fetchExisting(id) as NSManagedObject? else {
|
guard let object = context.fetchExisting(id) as NSManagedObject? else {
|
||||||
|
|
||||||
@@ -125,7 +143,9 @@ extension NSManagedObject: DynamicObject {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_matches(object: NSManagedObject) -> Bool {
|
public static func cs_matches(
|
||||||
|
object: NSManagedObject
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
return object.isKind(of: self)
|
return object.isKind(of: self)
|
||||||
}
|
}
|
||||||
@@ -148,7 +168,11 @@ extension CoreStoreObject {
|
|||||||
|
|
||||||
// MARK: DynamicObject
|
// MARK: DynamicObject
|
||||||
|
|
||||||
public class func cs_forceCreate(entityDescription: NSEntityDescription, into context: NSManagedObjectContext, assignTo store: NSPersistentStore) -> Self {
|
public class func cs_forceCreate(
|
||||||
|
entityDescription: NSEntityDescription,
|
||||||
|
into context: NSManagedObjectContext,
|
||||||
|
assignTo store: NSPersistentStore
|
||||||
|
) -> Self {
|
||||||
|
|
||||||
let type = NSClassFromString(entityDescription.managedObjectClassName!)! as! NSManagedObject.Type
|
let type = NSClassFromString(entityDescription.managedObjectClassName!)! as! NSManagedObject.Type
|
||||||
let object = type.init(entity: entityDescription, insertInto: context)
|
let object = type.init(entity: entityDescription, insertInto: context)
|
||||||
@@ -159,12 +183,19 @@ extension CoreStoreObject {
|
|||||||
return self.cs_fromRaw(object: object)
|
return self.cs_fromRaw(object: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
public class func cs_snapshotDictionary(id: ObjectID, context: NSManagedObjectContext) -> [String: Any]? {
|
public class func cs_snapshotDictionary(
|
||||||
|
id: ObjectID,
|
||||||
|
context: NSManagedObjectContext
|
||||||
|
) -> [String: Any]? {
|
||||||
|
|
||||||
var values: [KeyPathString: Any] = [:]
|
var values: [KeyPathString: Any] = [:]
|
||||||
if self.meta.needsReflection {
|
if self.meta.needsReflection {
|
||||||
|
|
||||||
func initializeAttributes(mirror: Mirror, object: Self, into attributes: inout [KeyPathString: Any]) {
|
func initializeAttributes(
|
||||||
|
mirror: Mirror,
|
||||||
|
object: Self,
|
||||||
|
into attributes: inout [KeyPathString: Any]
|
||||||
|
) {
|
||||||
|
|
||||||
if let superClassMirror = mirror.superclassMirror {
|
if let superClassMirror = mirror.superclassMirror {
|
||||||
|
|
||||||
@@ -267,7 +298,10 @@ extension CoreStoreObject {
|
|||||||
|
|
||||||
return unsafeDowncast(coreStoreObject, to: self)
|
return unsafeDowncast(coreStoreObject, to: self)
|
||||||
}
|
}
|
||||||
func forceTypeCast<T: CoreStoreObject>(_ type: AnyClass, to: T.Type) -> T.Type {
|
func forceTypeCast<T: CoreStoreObject>(
|
||||||
|
_ type: AnyClass,
|
||||||
|
to: T.Type
|
||||||
|
) -> T.Type {
|
||||||
|
|
||||||
return type as! T.Type
|
return type as! T.Type
|
||||||
}
|
}
|
||||||
@@ -276,7 +310,9 @@ extension CoreStoreObject {
|
|||||||
return coreStoreObject
|
return coreStoreObject
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_matches(object: NSManagedObject) -> Bool {
|
public static func cs_matches(
|
||||||
|
object: NSManagedObject
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
guard let type = object.entity.coreStoreEntity?.type else {
|
guard let type = object.entity.coreStoreEntity?.type else {
|
||||||
|
|
||||||
|
|||||||
+36
-5
@@ -70,7 +70,13 @@ public final class Entity<O: CoreStoreObject>: DynamicEntity {
|
|||||||
- parameter indexes: the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain `KeyPath`s to properties of the entity.
|
- parameter indexes: the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain `KeyPath`s to properties of the entity.
|
||||||
- parameter uniqueConstraints: sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more `KeyPath`s whose value must be unique over the set of instances of that entity. This value forms part of the entity's version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.
|
- parameter uniqueConstraints: sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more `KeyPath`s whose value must be unique over the set of instances of that entity. This value forms part of the entity's version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.
|
||||||
*/
|
*/
|
||||||
public convenience init(_ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = [], uniqueConstraints: [[PartialKeyPath<O>]]) {
|
public convenience init(
|
||||||
|
_ entityName: String,
|
||||||
|
isAbstract: Bool = false,
|
||||||
|
versionHashModifier: String? = nil,
|
||||||
|
indexes: [[PartialKeyPath<O>]] = [],
|
||||||
|
uniqueConstraints: [[PartialKeyPath<O>]]
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(
|
self.init(
|
||||||
O.self,
|
O.self,
|
||||||
@@ -92,7 +98,12 @@ public final class Entity<O: CoreStoreObject>: DynamicEntity {
|
|||||||
- parameter versionHashModifier: the version hash modifier for the entity. Used to mark or denote an entity as being a different "version" than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where, for example, the structure of an entity is unchanged but the format or content of data has changed.)
|
- parameter versionHashModifier: the version hash modifier for the entity. Used to mark or denote an entity as being a different "version" than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where, for example, the structure of an entity is unchanged but the format or content of data has changed.)
|
||||||
- parameter indexes: the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain `KeyPath`s to properties of the entity.
|
- parameter indexes: the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain `KeyPath`s to properties of the entity.
|
||||||
*/
|
*/
|
||||||
public convenience init(_ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = []) {
|
public convenience init(
|
||||||
|
_ entityName: String,
|
||||||
|
isAbstract: Bool = false,
|
||||||
|
versionHashModifier: String? = nil,
|
||||||
|
indexes: [[PartialKeyPath<O>]] = []
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(
|
self.init(
|
||||||
O.self,
|
O.self,
|
||||||
@@ -115,7 +126,14 @@ public final class Entity<O: CoreStoreObject>: DynamicEntity {
|
|||||||
- parameter indexes: the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain KeyPath's to properties of the entity.
|
- parameter indexes: the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain KeyPath's to properties of the entity.
|
||||||
- parameter uniqueConstraints: sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more `KeyPath`s whose value must be unique over the set of instances of that entity. This value forms part of the entity's version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.
|
- parameter uniqueConstraints: sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more `KeyPath`s whose value must be unique over the set of instances of that entity. This value forms part of the entity's version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.
|
||||||
*/
|
*/
|
||||||
public init(_ type: O.Type, _ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = [], uniqueConstraints: [[PartialKeyPath<O>]]) {
|
public init(
|
||||||
|
_ type: O.Type,
|
||||||
|
_ entityName: String,
|
||||||
|
isAbstract: Bool = false,
|
||||||
|
versionHashModifier: String? = nil,
|
||||||
|
indexes: [[PartialKeyPath<O>]] = [],
|
||||||
|
uniqueConstraints: [[PartialKeyPath<O>]]
|
||||||
|
) {
|
||||||
|
|
||||||
let meta = O.meta
|
let meta = O.meta
|
||||||
let toStringArray: ([PartialKeyPath<O>]) -> [KeyPathString] = {
|
let toStringArray: ([PartialKeyPath<O>]) -> [KeyPathString] = {
|
||||||
@@ -147,7 +165,13 @@ public final class Entity<O: CoreStoreObject>: DynamicEntity {
|
|||||||
- parameter indexes: the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain KeyPath's to properties of the entity.
|
- parameter indexes: the compound indexes for the entity as an array of arrays. The arrays contained in the returned array contain KeyPath's to properties of the entity.
|
||||||
- parameter uniqueConstraints: sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more `KeyPath`s whose value must be unique over the set of instances of that entity. This value forms part of the entity's version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.
|
- parameter uniqueConstraints: sets uniqueness constraints for the entity. A uniqueness constraint is a set of one or more `KeyPath`s whose value must be unique over the set of instances of that entity. This value forms part of the entity's version hash. Uniqueness constraint violations can be computationally expensive to handle. It is highly suggested that there be only one uniqueness constraint per entity hierarchy. Uniqueness constraints must be defined at the highest level possible, and CoreStore will raise an assertion failure if unique constraints are added to a sub entity.
|
||||||
*/
|
*/
|
||||||
public init(_ type: O.Type, _ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = []) {
|
public init(
|
||||||
|
_ type: O.Type,
|
||||||
|
_ entityName: String,
|
||||||
|
isAbstract: Bool = false,
|
||||||
|
versionHashModifier: String? = nil,
|
||||||
|
indexes: [[PartialKeyPath<O>]] = []
|
||||||
|
) {
|
||||||
|
|
||||||
let meta = O.meta
|
let meta = O.meta
|
||||||
let toStringArray: ([PartialKeyPath<O>]) -> [KeyPathString] = {
|
let toStringArray: ([PartialKeyPath<O>]) -> [KeyPathString] = {
|
||||||
@@ -232,7 +256,14 @@ public /*abstract*/ class DynamicEntity: Hashable {
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal init(type: DynamicObject.Type, entityName: String, isAbstract: Bool, versionHashModifier: String?, indexes: [[KeyPathString]], uniqueConstraints: [[KeyPathString]]) {
|
internal init(
|
||||||
|
type: DynamicObject.Type,
|
||||||
|
entityName: String,
|
||||||
|
isAbstract: Bool,
|
||||||
|
versionHashModifier: String?,
|
||||||
|
indexes: [[KeyPathString]],
|
||||||
|
uniqueConstraints: [[KeyPathString]]
|
||||||
|
) {
|
||||||
|
|
||||||
self.type = type
|
self.type = type
|
||||||
self.entityName = entityName
|
self.entityName = entityName
|
||||||
|
|||||||
@@ -57,27 +57,38 @@ public protocol FieldRelationshipType {
|
|||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_toReturnType(from value: NativeValueType?) -> Self
|
static func cs_toReturnType(
|
||||||
|
from value: NativeValueType?
|
||||||
|
) -> Self
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_toPublishedType(from value: SnapshotValueType, in context: NSManagedObjectContext) -> PublishedType
|
static func cs_toPublishedType(
|
||||||
|
from value: SnapshotValueType,
|
||||||
|
in context: NSManagedObjectContext
|
||||||
|
) -> PublishedType
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_toNativeType(from value: Self) -> NativeValueType?
|
static func cs_toNativeType(
|
||||||
|
from value: Self
|
||||||
|
) -> NativeValueType?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_toSnapshotType(from value: PublishedType) -> SnapshotValueType
|
static func cs_toSnapshotType(
|
||||||
|
from value: PublishedType
|
||||||
|
) -> SnapshotValueType
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Used internally by CoreStore. Do not call directly.
|
Used internally by CoreStore. Do not call directly.
|
||||||
*/
|
*/
|
||||||
static func cs_valueForSnapshot(from objectIDs: [DestinationObjectType.ObjectID]) -> SnapshotValueType
|
static func cs_valueForSnapshot(
|
||||||
|
from objectIDs: [DestinationObjectType.ObjectID]
|
||||||
|
) -> SnapshotValueType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -115,27 +126,38 @@ extension Optional: FieldRelationshipType, FieldRelationshipToOneType where Wrap
|
|||||||
|
|
||||||
public typealias PublishedType = ObjectPublisher<DestinationObjectType>?
|
public typealias PublishedType = ObjectPublisher<DestinationObjectType>?
|
||||||
|
|
||||||
public static func cs_toReturnType(from value: NativeValueType?) -> Self {
|
public static func cs_toReturnType(
|
||||||
|
from value: NativeValueType?
|
||||||
|
) -> Self {
|
||||||
|
|
||||||
return value.map(Wrapped.cs_fromRaw(object:))
|
return value.map(Wrapped.cs_fromRaw(object:))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toPublishedType(from value: SnapshotValueType, in context: NSManagedObjectContext) -> PublishedType {
|
public static func cs_toPublishedType(
|
||||||
|
from value: SnapshotValueType,
|
||||||
|
in context: NSManagedObjectContext
|
||||||
|
) -> PublishedType {
|
||||||
|
|
||||||
return value.map(context.objectPublisher(objectID:))
|
return value.map(context.objectPublisher(objectID:))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toNativeType(from value: Self) -> NativeValueType? {
|
public static func cs_toNativeType(
|
||||||
|
from value: Self
|
||||||
|
) -> NativeValueType? {
|
||||||
|
|
||||||
return value?.cs_toRaw()
|
return value?.cs_toRaw()
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toSnapshotType(from value: PublishedType) -> SnapshotValueType {
|
public static func cs_toSnapshotType(
|
||||||
|
from value: PublishedType
|
||||||
|
) -> SnapshotValueType {
|
||||||
|
|
||||||
return value?.objectID()
|
return value?.objectID()
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_valueForSnapshot(from objectIDs: [DestinationObjectType.ObjectID]) -> SnapshotValueType {
|
public static func cs_valueForSnapshot(
|
||||||
|
from objectIDs: [DestinationObjectType.ObjectID]
|
||||||
|
) -> SnapshotValueType {
|
||||||
|
|
||||||
return objectIDs.first
|
return objectIDs.first
|
||||||
}
|
}
|
||||||
@@ -156,7 +178,9 @@ extension Array: FieldRelationshipType, FieldRelationshipToManyType, FieldRelati
|
|||||||
|
|
||||||
public typealias PublishedType = [ObjectPublisher<DestinationObjectType>]
|
public typealias PublishedType = [ObjectPublisher<DestinationObjectType>]
|
||||||
|
|
||||||
public static func cs_toReturnType(from value: NativeValueType?) -> Self {
|
public static func cs_toReturnType(
|
||||||
|
from value: NativeValueType?
|
||||||
|
) -> Self {
|
||||||
|
|
||||||
guard let value = value else {
|
guard let value = value else {
|
||||||
|
|
||||||
@@ -165,22 +189,31 @@ extension Array: FieldRelationshipType, FieldRelationshipToManyType, FieldRelati
|
|||||||
return value.map({ Element.cs_fromRaw(object: $0 as! NSManagedObject) })
|
return value.map({ Element.cs_fromRaw(object: $0 as! NSManagedObject) })
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toPublishedType(from value: SnapshotValueType, in context: NSManagedObjectContext) -> PublishedType {
|
public static func cs_toPublishedType(
|
||||||
|
from value: SnapshotValueType,
|
||||||
|
in context: NSManagedObjectContext
|
||||||
|
) -> PublishedType {
|
||||||
|
|
||||||
return value.map(context.objectPublisher(objectID:))
|
return value.map(context.objectPublisher(objectID:))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toNativeType(from value: Self) -> NativeValueType? {
|
public static func cs_toNativeType(
|
||||||
|
from value: Self
|
||||||
|
) -> NativeValueType? {
|
||||||
|
|
||||||
return NSOrderedSet(array: value.map({ $0.rawObject! }))
|
return NSOrderedSet(array: value.map({ $0.rawObject! }))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toSnapshotType(from value: PublishedType) -> SnapshotValueType {
|
public static func cs_toSnapshotType(
|
||||||
|
from value: PublishedType
|
||||||
|
) -> SnapshotValueType {
|
||||||
|
|
||||||
return value.map({ $0.objectID() })
|
return value.map({ $0.objectID() })
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_valueForSnapshot(from objectIDs: [DestinationObjectType.ObjectID]) -> SnapshotValueType {
|
public static func cs_valueForSnapshot(
|
||||||
|
from objectIDs: [DestinationObjectType.ObjectID]
|
||||||
|
) -> SnapshotValueType {
|
||||||
|
|
||||||
return objectIDs
|
return objectIDs
|
||||||
}
|
}
|
||||||
@@ -201,7 +234,9 @@ extension Set: FieldRelationshipType, FieldRelationshipToManyType, FieldRelation
|
|||||||
|
|
||||||
public typealias PublishedType = Set<ObjectPublisher<DestinationObjectType>>
|
public typealias PublishedType = Set<ObjectPublisher<DestinationObjectType>>
|
||||||
|
|
||||||
public static func cs_toReturnType(from value: NativeValueType?) -> Self {
|
public static func cs_toReturnType(
|
||||||
|
from value: NativeValueType?
|
||||||
|
) -> Self {
|
||||||
|
|
||||||
guard let value = value else {
|
guard let value = value else {
|
||||||
|
|
||||||
@@ -210,22 +245,31 @@ extension Set: FieldRelationshipType, FieldRelationshipToManyType, FieldRelation
|
|||||||
return Set(value.map({ Element.cs_fromRaw(object: $0 as! NSManagedObject) }))
|
return Set(value.map({ Element.cs_fromRaw(object: $0 as! NSManagedObject) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toPublishedType(from value: SnapshotValueType, in context: NSManagedObjectContext) -> PublishedType {
|
public static func cs_toPublishedType(
|
||||||
|
from value: SnapshotValueType,
|
||||||
|
in context: NSManagedObjectContext
|
||||||
|
) -> PublishedType {
|
||||||
|
|
||||||
return PublishedType(value.map(context.objectPublisher(objectID:)))
|
return PublishedType(value.map(context.objectPublisher(objectID:)))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toNativeType(from value: Self) -> NativeValueType? {
|
public static func cs_toNativeType(
|
||||||
|
from value: Self
|
||||||
|
) -> NativeValueType? {
|
||||||
|
|
||||||
return NSSet(array: value.map({ $0.rawObject! }))
|
return NSSet(array: value.map({ $0.rawObject! }))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_toSnapshotType(from value: PublishedType) -> SnapshotValueType {
|
public static func cs_toSnapshotType(
|
||||||
|
from value: PublishedType
|
||||||
|
) -> SnapshotValueType {
|
||||||
|
|
||||||
return SnapshotValueType(value.map({ $0.objectID() }))
|
return SnapshotValueType(value.map({ $0.objectID() }))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func cs_valueForSnapshot(from objectIDs: [DestinationObjectType.ObjectID]) -> SnapshotValueType {
|
public static func cs_valueForSnapshot(
|
||||||
|
from objectIDs: [DestinationObjectType.ObjectID]
|
||||||
|
) -> SnapshotValueType {
|
||||||
|
|
||||||
return .init(objectIDs)
|
return .init(objectIDs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- parameter object: a reference to the object created/fetched outside the `FetchableSource`'s context
|
- parameter object: a reference to the object created/fetched outside the `FetchableSource`'s context
|
||||||
- returns: the `DynamicObject` instance if the object exists in the `FetchableSource`'s context, or `nil` if not found.
|
- returns: the `DynamicObject` instance if the object exists in the `FetchableSource`'s context, or `nil` if not found.
|
||||||
*/
|
*/
|
||||||
func fetchExisting<O: DynamicObject>(_ object: O) -> O?
|
func fetchExisting<O: DynamicObject>(
|
||||||
|
_ object: O
|
||||||
|
) -> O?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `DynamicObject` instance in the `FetchableSource`'s context from an `NSManagedObjectID`.
|
Fetches the `DynamicObject` instance in the `FetchableSource`'s context from an `NSManagedObjectID`.
|
||||||
@@ -48,7 +50,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object
|
- parameter objectID: the `NSManagedObjectID` for the object
|
||||||
- returns: the `DynamicObject` instance if the object exists in the `FetchableSource`, or `nil` if not found.
|
- returns: the `DynamicObject` instance if the object exists in the `FetchableSource`, or `nil` if not found.
|
||||||
*/
|
*/
|
||||||
func fetchExisting<O: DynamicObject>(_ objectID: NSManagedObjectID) -> O?
|
func fetchExisting<O: DynamicObject>(
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> O?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `DynamicObject` instances in the `FetchableSource`'s context from references created from another managed object context.
|
Fetches the `DynamicObject` instances in the `FetchableSource`'s context from references created from another managed object context.
|
||||||
@@ -56,7 +60,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- parameter objects: an array of `DynamicObject`s created/fetched outside the `FetchableSource`'s context
|
- parameter objects: an array of `DynamicObject`s created/fetched outside the `FetchableSource`'s context
|
||||||
- returns: the `DynamicObject` array for objects that exists in the `FetchableSource`
|
- returns: the `DynamicObject` array for objects that exists in the `FetchableSource`
|
||||||
*/
|
*/
|
||||||
func fetchExisting<O: DynamicObject, S: Sequence>(_ objects: S) -> [O] where S.Iterator.Element == O
|
func fetchExisting<O: DynamicObject, S: Sequence>(
|
||||||
|
_ objects: S
|
||||||
|
) -> [O] where S.Iterator.Element == O
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `DynamicObject` instances in the `FetchableSource`'s context from a list of `NSManagedObjectID`.
|
Fetches the `DynamicObject` instances in the `FetchableSource`'s context from a list of `NSManagedObjectID`.
|
||||||
@@ -64,7 +70,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
||||||
- returns: the `DynamicObject` array for objects that exists in the `FetchableSource`'s context
|
- returns: the `DynamicObject` array for objects that exists in the `FetchableSource`'s context
|
||||||
*/
|
*/
|
||||||
func fetchExisting<O: DynamicObject, S: Sequence>(_ objectIDs: S) -> [O] where S.Iterator.Element == NSManagedObjectID
|
func fetchExisting<O: DynamicObject, S: Sequence>(
|
||||||
|
_ objectIDs: S
|
||||||
|
) -> [O] where S.Iterator.Element == NSManagedObjectID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -74,7 +82,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchOne<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> O?
|
func fetchOne<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> O?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -84,7 +95,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchOne<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> O?
|
func fetchOne<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> O?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
|
Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||||
@@ -99,7 +113,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType?
|
func fetchOne<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> B.ObjectType?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -109,7 +125,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchAll<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [O]
|
func fetchAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> [O]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -119,7 +138,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchAll<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [O]
|
func fetchAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> [O]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||||
@@ -134,7 +156,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType]
|
func fetchAll<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [B.ObjectType]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -144,7 +168,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchCount<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> Int
|
func fetchCount<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -154,7 +181,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchCount<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> Int
|
func fetchCount<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||||
@@ -169,7 +199,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int
|
func fetchCount<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -179,7 +211,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID?
|
func fetchObjectID<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -189,7 +224,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID?
|
func fetchObjectID<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
|
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||||
@@ -204,7 +242,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> NSManagedObjectID?
|
func fetchObjectID<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -214,7 +254,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID]
|
func fetchObjectIDs<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
@@ -224,7 +267,10 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID]
|
func fetchObjectIDs<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
||||||
@@ -239,7 +285,9 @@ public protocol FetchableSource: AnyObject {
|
|||||||
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [NSManagedObjectID]
|
func fetchObjectIDs<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The internal `NSManagedObjectContext` managed by this `FetchableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
The internal `NSManagedObjectContext` managed by this `FetchableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
||||||
|
|||||||
+196
-33
@@ -127,8 +127,19 @@ extension FieldContainer {
|
|||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
coder fieldCoderType: Coder.Type,
|
coder fieldCoderType: Coder.Type,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
||||||
) where Coder.FieldStoredValue == V {
|
) where Coder.FieldStoredValue == V {
|
||||||
|
|
||||||
@@ -172,8 +183,19 @@ extension FieldContainer {
|
|||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
coder fieldCoderType: Coder.Type,
|
coder fieldCoderType: Coder.Type,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
||||||
dynamicInitialValue: @escaping () -> V
|
dynamicInitialValue: @escaping () -> V
|
||||||
) where Coder.FieldStoredValue == V {
|
) where Coder.FieldStoredValue == V {
|
||||||
@@ -276,9 +298,23 @@ extension FieldContainer {
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
coder: (encode: (V) -> Data?, decode: (Data?) -> V),
|
coder: (
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
encode: (V) -> Data?,
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
decode: (Data?) -> V
|
||||||
|
),
|
||||||
|
customGetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -328,9 +364,23 @@ extension FieldContainer {
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
coder: (encode: (V) -> Data?, decode: (Data?) -> V),
|
coder: (
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
encode: (V) -> Data?,
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
decode: (Data?) -> V
|
||||||
|
),
|
||||||
|
customGetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
||||||
dynamicInitialValue: @escaping () -> V
|
dynamicInitialValue: @escaping () -> V
|
||||||
) {
|
) {
|
||||||
@@ -428,7 +478,10 @@ extension FieldContainer {
|
|||||||
return ObjectType.self
|
return ObjectType.self
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func read(field: FieldProtocol, for rawObject: CoreStoreManagedObject) -> Any? {
|
internal static func read(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject
|
||||||
|
) -> Any? {
|
||||||
|
|
||||||
let field = field as! Self
|
let field = field as! Self
|
||||||
if let customGetter = field.customGetter {
|
if let customGetter = field.customGetter {
|
||||||
@@ -449,7 +502,11 @@ extension FieldContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func modify(field: FieldProtocol, for rawObject: CoreStoreManagedObject, newValue: Any?) {
|
internal static func modify(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject,
|
||||||
|
newValue: Any?
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
rawObject.isEditableInContext() == true,
|
rawObject.isEditableInContext() == true,
|
||||||
@@ -564,10 +621,22 @@ extension FieldContainer {
|
|||||||
versionHashModifier: @escaping () -> String?,
|
versionHashModifier: @escaping () -> String?,
|
||||||
renamingIdentifier: @escaping () -> String?,
|
renamingIdentifier: @escaping () -> String?,
|
||||||
valueTransformer: @escaping () -> Internals.AnyFieldCoder?,
|
valueTransformer: @escaping () -> Internals.AnyFieldCoder?,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)?,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? ,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)?,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? ,
|
||||||
dynamicInitialValue: (() -> V)?,
|
dynamicInitialValue: (() -> V)?,
|
||||||
affectedByKeyPaths: @escaping () -> Set<KeyPathString>) {
|
affectedByKeyPaths: @escaping () -> Set<KeyPathString>
|
||||||
|
) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.entityDescriptionValues = {
|
self.entityDescriptionValues = {
|
||||||
@@ -682,8 +751,19 @@ extension FieldContainer.Coded where V: FieldOptionalType {
|
|||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
coder: Coder.Type,
|
coder: Coder.Type,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
||||||
) where Coder.FieldStoredValue == V.Wrapped {
|
) where Coder.FieldStoredValue == V.Wrapped {
|
||||||
|
|
||||||
@@ -727,8 +807,19 @@ extension FieldContainer.Coded where V: FieldOptionalType {
|
|||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
coder: Coder.Type,
|
coder: Coder.Type,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
||||||
dynamicInitialValue: @escaping () -> V
|
dynamicInitialValue: @escaping () -> V
|
||||||
) where Coder.FieldStoredValue == V.Wrapped {
|
) where Coder.FieldStoredValue == V.Wrapped {
|
||||||
@@ -832,9 +923,23 @@ extension FieldContainer.Coded where V: FieldOptionalType {
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
coder: (encode: (V) -> Data?, decode: (Data?) -> V),
|
coder: (
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
encode: (V) -> Data?,
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
decode: (Data?) -> V
|
||||||
|
),
|
||||||
|
customGetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -884,9 +989,23 @@ extension FieldContainer.Coded where V: FieldOptionalType {
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
coder: (encode: (V) -> Data?, decode: (Data?) -> V),
|
coder: (
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
encode: (V) -> Data?,
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
decode: (Data?) -> V
|
||||||
|
),
|
||||||
|
customGetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
||||||
dynamicInitialValue: @escaping () -> V
|
dynamicInitialValue: @escaping () -> V
|
||||||
) {
|
) {
|
||||||
@@ -978,8 +1097,19 @@ extension FieldContainer.Coded where V: DefaultNSSecureCodable {
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -1020,8 +1150,19 @@ extension FieldContainer.Coded where V: DefaultNSSecureCodable {
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
||||||
dynamicInitialValue: @escaping () -> V
|
dynamicInitialValue: @escaping () -> V
|
||||||
) {
|
) {
|
||||||
@@ -1113,8 +1254,19 @@ extension FieldContainer.Coded where V: FieldOptionalType, V.Wrapped: DefaultNSS
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -1155,8 +1307,19 @@ extension FieldContainer.Coded where V: FieldOptionalType, V.Wrapped: DefaultNSS
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
||||||
dynamicInitialValue: @escaping () -> V
|
dynamicInitialValue: @escaping () -> V
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -167,7 +167,10 @@ extension FieldContainer {
|
|||||||
return ObjectType.self
|
return ObjectType.self
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func read(field: FieldProtocol, for rawObject: CoreStoreManagedObject) -> Any? {
|
internal static func read(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject
|
||||||
|
) -> Any? {
|
||||||
|
|
||||||
let field = field as! Self
|
let field = field as! Self
|
||||||
let keyPath = field.keyPath
|
let keyPath = field.keyPath
|
||||||
@@ -176,7 +179,11 @@ extension FieldContainer {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func modify(field: FieldProtocol, for rawObject: CoreStoreManagedObject, newValue: Any?) {
|
internal static func modify(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject,
|
||||||
|
newValue: Any?
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
rawObject.isEditableInContext() == true,
|
rawObject.isEditableInContext() == true,
|
||||||
@@ -196,7 +203,10 @@ extension FieldContainer {
|
|||||||
|
|
||||||
internal let entityDescriptionValues: () -> FieldRelationshipProtocol.EntityDescriptionValues
|
internal let entityDescriptionValues: () -> FieldRelationshipProtocol.EntityDescriptionValues
|
||||||
|
|
||||||
internal static func valueForSnapshot(field: FieldProtocol, for rawObject: CoreStoreManagedObject) -> Any? {
|
internal static func valueForSnapshot(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject
|
||||||
|
) -> Any? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
rawObject.isRunningInAllowedQueue() == true,
|
rawObject.isRunningInAllowedQueue() == true,
|
||||||
|
|||||||
@@ -116,8 +116,19 @@ extension FieldContainer {
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -157,8 +168,19 @@ extension FieldContainer {
|
|||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = [],
|
||||||
dynamicInitialValue: @escaping () -> V
|
dynamicInitialValue: @escaping () -> V
|
||||||
) {
|
) {
|
||||||
@@ -255,7 +277,10 @@ extension FieldContainer {
|
|||||||
return ObjectType.self
|
return ObjectType.self
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func read(field: FieldProtocol, for rawObject: CoreStoreManagedObject) -> Any? {
|
internal static func read(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject
|
||||||
|
) -> Any? {
|
||||||
|
|
||||||
let field = field as! Self
|
let field = field as! Self
|
||||||
if let customGetter = field.customGetter {
|
if let customGetter = field.customGetter {
|
||||||
@@ -276,7 +301,10 @@ extension FieldContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func modify(field: FieldProtocol, for rawObject: CoreStoreManagedObject, newValue: Any?) {
|
internal static func modify(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject, newValue: Any?
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
rawObject.isEditableInContext() == true,
|
rawObject.isEditableInContext() == true,
|
||||||
@@ -379,7 +407,8 @@ extension FieldContainer {
|
|||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)?,
|
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)?,
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)?,
|
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)?,
|
||||||
dynamicInitialValue: (() -> V)?,
|
dynamicInitialValue: (() -> V)?,
|
||||||
affectedByKeyPaths: @escaping () -> Set<KeyPathString>) {
|
affectedByKeyPaths: @escaping () -> Set<KeyPathString>
|
||||||
|
) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.entityDescriptionValues = {
|
self.entityDescriptionValues = {
|
||||||
@@ -403,8 +432,19 @@ extension FieldContainer {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private let customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)?
|
private let customGetter: (
|
||||||
private let customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)?
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)?
|
||||||
|
private let customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)?
|
||||||
private let dynamicInitialValue: (() -> V)?
|
private let dynamicInitialValue: (() -> V)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-10
@@ -80,7 +80,13 @@ extension FieldContainer {
|
|||||||
public init(
|
public init(
|
||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
customGetter: @escaping (_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V,
|
customGetter: @escaping (_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V,
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []) {
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []) {
|
||||||
|
|
||||||
self.init(
|
self.init(
|
||||||
@@ -99,8 +105,19 @@ extension FieldContainer {
|
|||||||
wrappedValue initial: @autoclosure @escaping () -> V,
|
wrappedValue initial: @autoclosure @escaping () -> V,
|
||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []) {
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []) {
|
||||||
|
|
||||||
fatalError()
|
fatalError()
|
||||||
@@ -185,7 +202,10 @@ extension FieldContainer {
|
|||||||
return ObjectType.self
|
return ObjectType.self
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func read(field: FieldProtocol, for rawObject: CoreStoreManagedObject) -> Any? {
|
internal static func read(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject
|
||||||
|
) -> Any? {
|
||||||
|
|
||||||
let field = field as! Self
|
let field = field as! Self
|
||||||
if let customGetter = field.customGetter {
|
if let customGetter = field.customGetter {
|
||||||
@@ -206,7 +226,11 @@ extension FieldContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func modify(field: FieldProtocol, for rawObject: CoreStoreManagedObject, newValue: Any?) {
|
internal static func modify(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject,
|
||||||
|
newValue: Any?
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
rawObject.isEditableInContext() == true,
|
rawObject.isEditableInContext() == true,
|
||||||
@@ -285,7 +309,8 @@ extension FieldContainer {
|
|||||||
keyPath: KeyPathString,
|
keyPath: KeyPathString,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)?,
|
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)?,
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? ,
|
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? ,
|
||||||
affectedByKeyPaths: @escaping () -> Set<KeyPathString>) {
|
affectedByKeyPaths: @escaping () -> Set<KeyPathString>
|
||||||
|
) {
|
||||||
|
|
||||||
self.keyPath = keyPath
|
self.keyPath = keyPath
|
||||||
self.entityDescriptionValues = {
|
self.entityDescriptionValues = {
|
||||||
@@ -308,8 +333,19 @@ extension FieldContainer {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private let customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)?
|
private let customGetter: (
|
||||||
private let customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)?
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)?
|
||||||
|
private let customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,8 +378,19 @@ extension FieldContainer.Virtual where V: FieldOptionalType {
|
|||||||
*/
|
*/
|
||||||
public init(
|
public init(
|
||||||
_ keyPath: KeyPathString,
|
_ keyPath: KeyPathString,
|
||||||
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
|
customGetter: (
|
||||||
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>
|
||||||
|
) -> V
|
||||||
|
)? = nil,
|
||||||
|
customSetter: (
|
||||||
|
(
|
||||||
|
_ object: ObjectProxy<O>,
|
||||||
|
_ field: ObjectProxy<O>.FieldProxy<V>,
|
||||||
|
_ newValue: V
|
||||||
|
) -> Void
|
||||||
|
)? = nil,
|
||||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []) {
|
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []) {
|
||||||
|
|
||||||
self.init(
|
self.init(
|
||||||
|
|||||||
@@ -33,6 +33,14 @@ internal protocol FieldProtocol: PropertyProtocol {
|
|||||||
|
|
||||||
static var dynamicObjectType: CoreStoreObject.Type { get }
|
static var dynamicObjectType: CoreStoreObject.Type { get }
|
||||||
|
|
||||||
static func read(field: FieldProtocol, for rawObject: CoreStoreManagedObject) -> Any?
|
static func read(
|
||||||
static func modify(field: FieldProtocol, for rawObject: CoreStoreManagedObject, newValue: Any?)
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject
|
||||||
|
) -> Any?
|
||||||
|
|
||||||
|
static func modify(
|
||||||
|
field: FieldProtocol,
|
||||||
|
for rawObject: CoreStoreManagedObject,
|
||||||
|
newValue: Any?
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+214
-68
@@ -37,7 +37,9 @@ extension From {
|
|||||||
- parameter clause: the `Where` clause to create a `FetchChainBuilder` with
|
- parameter clause: the `Where` clause to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that starts with the specified `Where` clause
|
- returns: a `FetchChainBuilder` that starts with the specified `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(_ clause: Where<O>) -> FetchChainBuilder<O> {
|
public func `where`(
|
||||||
|
_ clause: Where<O>
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clause)
|
return self.fetchChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -48,7 +50,9 @@ extension From {
|
|||||||
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses
|
- returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses
|
||||||
*/
|
*/
|
||||||
public func `where`(combineByAnd clauses: Where<O>...) -> FetchChainBuilder<O> {
|
public func `where`(
|
||||||
|
combineByAnd clauses: Where<O>...
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clauses.combinedByAnd())
|
return self.fetchChain(appending: clauses.combinedByAnd())
|
||||||
}
|
}
|
||||||
@@ -59,7 +63,9 @@ extension From {
|
|||||||
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses
|
- returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses
|
||||||
*/
|
*/
|
||||||
public func `where`(combineByOr clauses: Where<O>...) -> FetchChainBuilder<O> {
|
public func `where`(
|
||||||
|
combineByOr clauses: Where<O>...
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clauses.combinedByOr())
|
return self.fetchChain(appending: clauses.combinedByOr())
|
||||||
}
|
}
|
||||||
@@ -100,7 +106,9 @@ extension From {
|
|||||||
- parameter clause: the `OrderBy` clause to create a `FetchChainBuilder` with
|
- parameter clause: the `OrderBy` clause to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that starts with the specified `OrderBy` clause
|
- returns: a `FetchChainBuilder` that starts with the specified `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ clause: OrderBy<O>) -> FetchChainBuilder<O> {
|
public func orderBy(
|
||||||
|
_ clause: OrderBy<O>
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clause)
|
return self.fetchChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -126,7 +134,9 @@ extension From {
|
|||||||
- parameter sortKeys: a series of `SortKey`s
|
- parameter sortKeys: a series of `SortKey`s
|
||||||
- returns: a `FetchChainBuilder` with a series of `SortKey`s
|
- returns: a `FetchChainBuilder` with a series of `SortKey`s
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ sortKeys: [OrderBy<O>.SortKey]) -> FetchChainBuilder<O> {
|
public func orderBy(
|
||||||
|
_ sortKeys: [OrderBy<O>.SortKey]
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: OrderBy<O>(sortKeys))
|
return self.fetchChain(appending: OrderBy<O>(sortKeys))
|
||||||
}
|
}
|
||||||
@@ -137,7 +147,9 @@ extension From {
|
|||||||
- parameter fetchRequest: the block to customize the `NSFetchRequest`
|
- parameter fetchRequest: the block to customize the `NSFetchRequest`
|
||||||
- returns: a `FetchChainBuilder` with closure where the `NSFetchRequest` may be configured
|
- returns: a `FetchChainBuilder` with closure where the `NSFetchRequest` may be configured
|
||||||
*/
|
*/
|
||||||
public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> FetchChainBuilder<O> {
|
public func tweak(
|
||||||
|
_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: Tweak(fetchRequest))
|
return self.fetchChain(appending: Tweak(fetchRequest))
|
||||||
}
|
}
|
||||||
@@ -148,7 +160,9 @@ extension From {
|
|||||||
- parameter clause: the `FetchClause` to add to the `FetchChainBuilder`
|
- parameter clause: the `FetchClause` to add to the `FetchChainBuilder`
|
||||||
- returns: a `FetchChainBuilder` containing the specified `FetchClause`
|
- returns: a `FetchChainBuilder` containing the specified `FetchClause`
|
||||||
*/
|
*/
|
||||||
public func appending(_ clause: FetchClause) -> FetchChainBuilder<O> {
|
public func appending(
|
||||||
|
_ clause: FetchClause
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clause)
|
return self.fetchChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -159,7 +173,9 @@ extension From {
|
|||||||
- parameter clauses: the `FetchClause`s to add to the `FetchChainBuilder`
|
- parameter clauses: the `FetchClause`s to add to the `FetchChainBuilder`
|
||||||
- returns: a `FetchChainBuilder` containing the specified `FetchClause`s
|
- returns: a `FetchChainBuilder` containing the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func appending<S: Sequence>(contentsOf clauses: S) -> FetchChainBuilder<O> where S.Element == FetchClause {
|
public func appending<S: Sequence>(
|
||||||
|
contentsOf clauses: S
|
||||||
|
) -> FetchChainBuilder<O> where S.Element == FetchClause {
|
||||||
|
|
||||||
return self.fetchChain(appending: clauses)
|
return self.fetchChain(appending: clauses)
|
||||||
}
|
}
|
||||||
@@ -170,7 +186,9 @@ extension From {
|
|||||||
- parameter clause: the `Select` clause to create a `QueryChainBuilder` with
|
- parameter clause: the `Select` clause to create a `QueryChainBuilder` with
|
||||||
- returns: a `QueryChainBuilder` that starts with the specified `Select` clause
|
- returns: a `QueryChainBuilder` that starts with the specified `Select` clause
|
||||||
*/
|
*/
|
||||||
public func select<R>(_ clause: Select<O, R>) -> QueryChainBuilder<O, R> {
|
public func select<R>(
|
||||||
|
_ clause: Select<O, R>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
from: self,
|
from: self,
|
||||||
@@ -221,7 +239,9 @@ extension From {
|
|||||||
- parameter clause: the `SectionBy` to be used by the `ListMonitor`
|
- parameter clause: the `SectionBy` to be used by the `ListMonitor`
|
||||||
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
||||||
*/
|
*/
|
||||||
public func sectionBy(_ clause: SectionBy<O>) -> SectionMonitorChainBuilder<O> {
|
public func sectionBy(
|
||||||
|
_ clause: SectionBy<O>
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
from: self,
|
from: self,
|
||||||
@@ -236,7 +256,9 @@ extension From {
|
|||||||
- parameter sectionKeyPath: the key path to use to group the objects into sections
|
- parameter sectionKeyPath: the key path to use to group the objects into sections
|
||||||
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
||||||
*/
|
*/
|
||||||
public func sectionBy(_ sectionKeyPath: KeyPathString) -> SectionMonitorChainBuilder<O> {
|
public func sectionBy(
|
||||||
|
_ sectionKeyPath: KeyPathString
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionBy(sectionKeyPath, sectionIndexTransformer: { _ in nil })
|
return self.sectionBy(sectionKeyPath, sectionIndexTransformer: { _ in nil })
|
||||||
}
|
}
|
||||||
@@ -267,12 +289,16 @@ extension From {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private func fetchChain(appending clause: FetchClause) -> FetchChainBuilder<O> {
|
private func fetchChain(
|
||||||
|
appending clause: FetchClause
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return .init(from: self, fetchClauses: [clause])
|
return .init(from: self, fetchClauses: [clause])
|
||||||
}
|
}
|
||||||
|
|
||||||
private func fetchChain<S: Sequence>(appending clauses: S) -> FetchChainBuilder<O> where S.Element == FetchClause {
|
private func fetchChain<S: Sequence>(
|
||||||
|
appending clauses: S
|
||||||
|
) -> FetchChainBuilder<O> where S.Element == FetchClause {
|
||||||
|
|
||||||
return .init(from: self, fetchClauses: Array(clauses))
|
return .init(from: self, fetchClauses: Array(clauses))
|
||||||
}
|
}
|
||||||
@@ -289,7 +315,9 @@ extension From where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to query the value for
|
- parameter keyPath: the keyPath to query the value for
|
||||||
- returns: a `QueryChainBuilder` that starts with a `Select` clause created from the specified key path
|
- returns: a `QueryChainBuilder` that starts with a `Select` clause created from the specified key path
|
||||||
*/
|
*/
|
||||||
public func select<R>(_ keyPath: KeyPath<O, R>) -> QueryChainBuilder<O, R> {
|
public func select<R>(
|
||||||
|
_ keyPath: KeyPath<O, R>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.select(R.self, [SelectTerm<O>.attribute(keyPath)])
|
return self.select(R.self, [SelectTerm<O>.attribute(keyPath)])
|
||||||
}
|
}
|
||||||
@@ -300,7 +328,9 @@ extension From where O: NSManagedObject {
|
|||||||
- parameter sectionKeyPath: the `KeyPath` to use to group the objects into sections
|
- parameter sectionKeyPath: the `KeyPath` to use to group the objects into sections
|
||||||
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
||||||
*/
|
*/
|
||||||
public func sectionBy<T>(_ sectionKeyPath: KeyPath<O, T>) -> SectionMonitorChainBuilder<O> {
|
public func sectionBy<T>(
|
||||||
|
_ sectionKeyPath: KeyPath<O, T>
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionBy(
|
return self.sectionBy(
|
||||||
sectionKeyPath._kvcKeyPathString!,
|
sectionKeyPath._kvcKeyPathString!,
|
||||||
@@ -339,7 +369,9 @@ extension From where O: CoreStoreObject {
|
|||||||
- parameter clause: a closure that returns a `Where` clause
|
- parameter clause: a closure that returns a `Where` clause
|
||||||
- returns: a `FetchChainBuilder` that starts with the specified `Where` clause
|
- returns: a `FetchChainBuilder` that starts with the specified `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`<T: AnyWhereClause>(_ clause: (O) -> T) -> FetchChainBuilder<O> {
|
public func `where`<T: AnyWhereClause>(
|
||||||
|
_ clause: (O) -> T
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clause(O.meta))
|
return self.fetchChain(appending: clause(O.meta))
|
||||||
}
|
}
|
||||||
@@ -350,7 +382,9 @@ extension From where O: CoreStoreObject {
|
|||||||
- parameter sectionKeyPath: the `KeyPath` to use to group the objects into sections
|
- parameter sectionKeyPath: the `KeyPath` to use to group the objects into sections
|
||||||
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
||||||
*/
|
*/
|
||||||
public func sectionBy<T>(_ sectionKeyPath: KeyPath<O, FieldContainer<O>.Stored<T>>) -> SectionMonitorChainBuilder<O> {
|
public func sectionBy<T>(
|
||||||
|
_ sectionKeyPath: KeyPath<O, FieldContainer<O>.Stored<T>>
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionBy(
|
return self.sectionBy(
|
||||||
O.meta[keyPath: sectionKeyPath].keyPath,
|
O.meta[keyPath: sectionKeyPath].keyPath,
|
||||||
@@ -364,7 +398,9 @@ extension From where O: CoreStoreObject {
|
|||||||
- parameter sectionKeyPath: the `KeyPath` to use to group the objects into sections
|
- parameter sectionKeyPath: the `KeyPath` to use to group the objects into sections
|
||||||
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
||||||
*/
|
*/
|
||||||
public func sectionBy<T>(_ sectionKeyPath: KeyPath<O, FieldContainer<O>.Virtual<T>>) -> SectionMonitorChainBuilder<O> {
|
public func sectionBy<T>(
|
||||||
|
_ sectionKeyPath: KeyPath<O, FieldContainer<O>.Virtual<T>>
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionBy(
|
return self.sectionBy(
|
||||||
O.meta[keyPath: sectionKeyPath].keyPath,
|
O.meta[keyPath: sectionKeyPath].keyPath,
|
||||||
@@ -378,7 +414,9 @@ extension From where O: CoreStoreObject {
|
|||||||
- parameter sectionKeyPath: the `KeyPath` to use to group the objects into sections
|
- parameter sectionKeyPath: the `KeyPath` to use to group the objects into sections
|
||||||
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
- returns: a `SectionMonitorChainBuilder` that is sectioned by the specified key path
|
||||||
*/
|
*/
|
||||||
public func sectionBy<T>(_ sectionKeyPath: KeyPath<O, FieldContainer<O>.Coded<T>>) -> SectionMonitorChainBuilder<O> {
|
public func sectionBy<T>(
|
||||||
|
_ sectionKeyPath: KeyPath<O, FieldContainer<O>.Coded<T>>
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionBy(
|
return self.sectionBy(
|
||||||
O.meta[keyPath: sectionKeyPath].keyPath,
|
O.meta[keyPath: sectionKeyPath].keyPath,
|
||||||
@@ -455,7 +493,9 @@ extension FetchChainBuilder {
|
|||||||
- parameter clause: a `Where` clause to add to the fetch builder
|
- parameter clause: a `Where` clause to add to the fetch builder
|
||||||
- returns: a new `FetchChainBuilder` containing the `Where` clause
|
- returns: a new `FetchChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(_ clause: Where<O>) -> FetchChainBuilder<O> {
|
public func `where`(
|
||||||
|
_ clause: Where<O>
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clause)
|
return self.fetchChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -466,7 +506,9 @@ extension FetchChainBuilder {
|
|||||||
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses
|
- returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses
|
||||||
*/
|
*/
|
||||||
public func `where`(combineByAnd clauses: Where<O>...) -> FetchChainBuilder<O> {
|
public func `where`(
|
||||||
|
combineByAnd clauses: Where<O>...
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clauses.combinedByAnd())
|
return self.fetchChain(appending: clauses.combinedByAnd())
|
||||||
}
|
}
|
||||||
@@ -477,7 +519,9 @@ extension FetchChainBuilder {
|
|||||||
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses
|
- returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses
|
||||||
*/
|
*/
|
||||||
public func `where`(combineByOr clauses: Where<O>...) -> FetchChainBuilder<O> {
|
public func `where`(
|
||||||
|
combineByOr clauses: Where<O>...
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clauses.combinedByOr())
|
return self.fetchChain(appending: clauses.combinedByOr())
|
||||||
}
|
}
|
||||||
@@ -489,7 +533,10 @@ extension FetchChainBuilder {
|
|||||||
- parameter args: the arguments for `format`
|
- parameter args: the arguments for `format`
|
||||||
- returns: a new `FetchChainBuilder` containing the `Where` clause
|
- returns: a new `FetchChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(format: String, _ args: Any...) -> FetchChainBuilder<O> {
|
public func `where`(
|
||||||
|
format: String,
|
||||||
|
_ args: Any...
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: Where<O>(format, argumentArray: args))
|
return self.fetchChain(appending: Where<O>(format, argumentArray: args))
|
||||||
}
|
}
|
||||||
@@ -501,7 +548,10 @@ extension FetchChainBuilder {
|
|||||||
- parameter argumentArray: the arguments for `format`
|
- parameter argumentArray: the arguments for `format`
|
||||||
- returns: a new `FetchChainBuilder` containing the `Where` clause
|
- returns: a new `FetchChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(format: String, argumentArray: [Any]?) -> FetchChainBuilder<O> {
|
public func `where`(
|
||||||
|
format: String,
|
||||||
|
argumentArray: [Any]?
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: Where<O>(format, argumentArray: argumentArray))
|
return self.fetchChain(appending: Where<O>(format, argumentArray: argumentArray))
|
||||||
}
|
}
|
||||||
@@ -512,7 +562,9 @@ extension FetchChainBuilder {
|
|||||||
- parameter clause: the `OrderBy` clause to add
|
- parameter clause: the `OrderBy` clause to add
|
||||||
- returns: a new `FetchChainBuilder` containing the `OrderBy` clause
|
- returns: a new `FetchChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ clause: OrderBy<O>) -> FetchChainBuilder<O> {
|
public func orderBy(
|
||||||
|
_ clause: OrderBy<O>
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clause)
|
return self.fetchChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -524,7 +576,10 @@ extension FetchChainBuilder {
|
|||||||
- parameter sortKeys: a series of other `SortKey`s
|
- parameter sortKeys: a series of other `SortKey`s
|
||||||
- returns: a new `FetchChainBuilder` containing the `OrderBy` clause
|
- returns: a new `FetchChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ sortKey: OrderBy<O>.SortKey, _ sortKeys: OrderBy<O>.SortKey...) -> FetchChainBuilder<O> {
|
public func orderBy(
|
||||||
|
_ sortKey: OrderBy<O>.SortKey,
|
||||||
|
_ sortKeys: OrderBy<O>.SortKey...
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: OrderBy<O>([sortKey] + sortKeys))
|
return self.fetchChain(appending: OrderBy<O>([sortKey] + sortKeys))
|
||||||
}
|
}
|
||||||
@@ -535,7 +590,9 @@ extension FetchChainBuilder {
|
|||||||
- parameter sortKeys: a series of `SortKey`s
|
- parameter sortKeys: a series of `SortKey`s
|
||||||
- returns: a new `FetchChainBuilder` containing the `OrderBy` clause
|
- returns: a new `FetchChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ sortKeys: [OrderBy<O>.SortKey]) -> FetchChainBuilder<O> {
|
public func orderBy(
|
||||||
|
_ sortKeys: [OrderBy<O>.SortKey]
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: OrderBy<O>(sortKeys))
|
return self.fetchChain(appending: OrderBy<O>(sortKeys))
|
||||||
}
|
}
|
||||||
@@ -546,7 +603,9 @@ extension FetchChainBuilder {
|
|||||||
- parameter fetchRequest: the block to customize the `NSFetchRequest`
|
- parameter fetchRequest: the block to customize the `NSFetchRequest`
|
||||||
- returns: a new `FetchChainBuilder` containing the `Tweak` clause
|
- returns: a new `FetchChainBuilder` containing the `Tweak` clause
|
||||||
*/
|
*/
|
||||||
public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> FetchChainBuilder<O> {
|
public func tweak(
|
||||||
|
_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: Tweak(fetchRequest))
|
return self.fetchChain(appending: Tweak(fetchRequest))
|
||||||
}
|
}
|
||||||
@@ -557,7 +616,9 @@ extension FetchChainBuilder {
|
|||||||
- parameter clause: the `FetchClause` to add to the `FetchChainBuilder`
|
- parameter clause: the `FetchClause` to add to the `FetchChainBuilder`
|
||||||
- returns: a new `FetchChainBuilder` containing the `FetchClause`
|
- returns: a new `FetchChainBuilder` containing the `FetchClause`
|
||||||
*/
|
*/
|
||||||
public func appending(_ clause: FetchClause) -> FetchChainBuilder<O> {
|
public func appending(
|
||||||
|
_ clause: FetchClause
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clause)
|
return self.fetchChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -568,7 +629,9 @@ extension FetchChainBuilder {
|
|||||||
- parameter clauses: the `FetchClause`s to add to the `FetchChainBuilder`
|
- parameter clauses: the `FetchClause`s to add to the `FetchChainBuilder`
|
||||||
- returns: a new `FetchChainBuilder` containing the `FetchClause`s
|
- returns: a new `FetchChainBuilder` containing the `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func appending<S: Sequence>(contentsOf clauses: S) -> FetchChainBuilder<O> where S.Element == FetchClause {
|
public func appending<S: Sequence>(
|
||||||
|
contentsOf clauses: S
|
||||||
|
) -> FetchChainBuilder<O> where S.Element == FetchClause {
|
||||||
|
|
||||||
return self.fetchChain(appending: clauses)
|
return self.fetchChain(appending: clauses)
|
||||||
}
|
}
|
||||||
@@ -576,7 +639,9 @@ extension FetchChainBuilder {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private func fetchChain(appending clause: FetchClause) -> FetchChainBuilder<O> {
|
private func fetchChain(
|
||||||
|
appending clause: FetchClause
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
from: self.from,
|
from: self.from,
|
||||||
@@ -584,7 +649,9 @@ extension FetchChainBuilder {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func fetchChain<S: Sequence>(appending clauses: S) -> FetchChainBuilder<O> where S.Element == FetchClause {
|
private func fetchChain<S: Sequence>(
|
||||||
|
appending clauses: S
|
||||||
|
) -> FetchChainBuilder<O> where S.Element == FetchClause {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
from: self.from,
|
from: self.from,
|
||||||
@@ -598,7 +665,9 @@ extension FetchChainBuilder {
|
|||||||
|
|
||||||
extension FetchChainBuilder where O: CoreStoreObject {
|
extension FetchChainBuilder where O: CoreStoreObject {
|
||||||
|
|
||||||
public func `where`<T: AnyWhereClause>(_ clause: (O) -> T) -> FetchChainBuilder<O> {
|
public func `where`<T: AnyWhereClause>(
|
||||||
|
_ clause: (O) -> T
|
||||||
|
) -> FetchChainBuilder<O> {
|
||||||
|
|
||||||
return self.fetchChain(appending: clause(O.meta))
|
return self.fetchChain(appending: clause(O.meta))
|
||||||
}
|
}
|
||||||
@@ -615,7 +684,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter clause: a `Where` clause to add to the query builder
|
- parameter clause: a `Where` clause to add to the query builder
|
||||||
- returns: a new `QueryChainBuilder` containing the `Where` clause
|
- returns: a new `QueryChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(_ clause: Where<O>) -> QueryChainBuilder<O, R> {
|
public func `where`(
|
||||||
|
_ clause: Where<O>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: clause)
|
return self.queryChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -626,7 +697,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses
|
- returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses
|
||||||
*/
|
*/
|
||||||
public func `where`(combineByAnd clauses: Where<O>...) -> QueryChainBuilder<O, R> {
|
public func `where`(
|
||||||
|
combineByAnd clauses: Where<O>...
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: clauses.combinedByAnd())
|
return self.queryChain(appending: clauses.combinedByAnd())
|
||||||
}
|
}
|
||||||
@@ -637,7 +710,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses
|
- returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses
|
||||||
*/
|
*/
|
||||||
public func `where`(combineByOr clauses: Where<O>...) -> QueryChainBuilder<O, R> {
|
public func `where`(
|
||||||
|
combineByOr clauses: Where<O>...
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: clauses.combinedByOr())
|
return self.queryChain(appending: clauses.combinedByOr())
|
||||||
}
|
}
|
||||||
@@ -649,7 +724,10 @@ extension QueryChainBuilder {
|
|||||||
- parameter args: the arguments for `format`
|
- parameter args: the arguments for `format`
|
||||||
- returns: a new `QueryChainBuilder` containing the `Where` clause
|
- returns: a new `QueryChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(format: String, _ args: Any...) -> QueryChainBuilder<O, R> {
|
public func `where`(
|
||||||
|
format: String,
|
||||||
|
_ args: Any...
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: Where<O>(format, argumentArray: args))
|
return self.queryChain(appending: Where<O>(format, argumentArray: args))
|
||||||
}
|
}
|
||||||
@@ -661,7 +739,10 @@ extension QueryChainBuilder {
|
|||||||
- parameter argumentArray: the arguments for `format`
|
- parameter argumentArray: the arguments for `format`
|
||||||
- returns: a new `QueryChainBuilder` containing the `Where` clause
|
- returns: a new `QueryChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(format: String, argumentArray: [Any]?) -> QueryChainBuilder<O, R> {
|
public func `where`(
|
||||||
|
format: String,
|
||||||
|
argumentArray: [Any]?
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: Where<O>(format, argumentArray: argumentArray))
|
return self.queryChain(appending: Where<O>(format, argumentArray: argumentArray))
|
||||||
}
|
}
|
||||||
@@ -672,7 +753,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter clause: the `OrderBy` clause to add
|
- parameter clause: the `OrderBy` clause to add
|
||||||
- returns: a new `QueryChainBuilder` containing the `OrderBy` clause
|
- returns: a new `QueryChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ clause: OrderBy<O>) -> QueryChainBuilder<O, R> {
|
public func orderBy(
|
||||||
|
_ clause: OrderBy<O>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: clause)
|
return self.queryChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -684,7 +767,10 @@ extension QueryChainBuilder {
|
|||||||
- parameter sortKeys: a series of other `SortKey`s
|
- parameter sortKeys: a series of other `SortKey`s
|
||||||
- returns: a new `QueryChainBuilder` containing the `OrderBy` clause
|
- returns: a new `QueryChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ sortKey: OrderBy<O>.SortKey, _ sortKeys: OrderBy<O>.SortKey...) -> QueryChainBuilder<O, R> {
|
public func orderBy(
|
||||||
|
_ sortKey: OrderBy<O>.SortKey,
|
||||||
|
_ sortKeys: OrderBy<O>.SortKey...
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: OrderBy<O>([sortKey] + sortKeys))
|
return self.queryChain(appending: OrderBy<O>([sortKey] + sortKeys))
|
||||||
}
|
}
|
||||||
@@ -695,7 +781,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter sortKeys: a series of `SortKey`s
|
- parameter sortKeys: a series of `SortKey`s
|
||||||
- returns: a new `QueryChainBuilder` containing the `OrderBy` clause
|
- returns: a new `QueryChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ sortKeys: [OrderBy<O>.SortKey]) -> QueryChainBuilder<O, R> {
|
public func orderBy(
|
||||||
|
_ sortKeys: [OrderBy<O>.SortKey]
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: OrderBy<O>(sortKeys))
|
return self.queryChain(appending: OrderBy<O>(sortKeys))
|
||||||
}
|
}
|
||||||
@@ -706,7 +794,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter fetchRequest: the block to customize the `NSFetchRequest`
|
- parameter fetchRequest: the block to customize the `NSFetchRequest`
|
||||||
- returns: a new `QueryChainBuilder` containing the `Tweak` clause
|
- returns: a new `QueryChainBuilder` containing the `Tweak` clause
|
||||||
*/
|
*/
|
||||||
public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> QueryChainBuilder<O, R> {
|
public func tweak(
|
||||||
|
_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: Tweak(fetchRequest))
|
return self.queryChain(appending: Tweak(fetchRequest))
|
||||||
}
|
}
|
||||||
@@ -717,7 +807,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter clause: a `GroupBy` clause to add to the query builder
|
- parameter clause: a `GroupBy` clause to add to the query builder
|
||||||
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
||||||
*/
|
*/
|
||||||
public func groupBy(_ clause: GroupBy<O>) -> QueryChainBuilder<O, R> {
|
public func groupBy(
|
||||||
|
_ clause: GroupBy<O>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: clause)
|
return self.queryChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -729,7 +821,10 @@ extension QueryChainBuilder {
|
|||||||
- parameter keyPaths: other key paths to group the query results with
|
- parameter keyPaths: other key paths to group the query results with
|
||||||
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
||||||
*/
|
*/
|
||||||
public func groupBy(_ keyPath: KeyPathString, _ keyPaths: KeyPathString...) -> QueryChainBuilder<O, R> {
|
public func groupBy(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
_ keyPaths: KeyPathString...
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.groupBy(GroupBy<O>([keyPath] + keyPaths))
|
return self.groupBy(GroupBy<O>([keyPath] + keyPaths))
|
||||||
}
|
}
|
||||||
@@ -740,7 +835,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter keyPaths: a series of key paths to group the query results with
|
- parameter keyPaths: a series of key paths to group the query results with
|
||||||
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
||||||
*/
|
*/
|
||||||
public func groupBy(_ keyPaths: [KeyPathString]) -> QueryChainBuilder<O, R> {
|
public func groupBy(
|
||||||
|
_ keyPaths: [KeyPathString]
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: GroupBy<O>(keyPaths))
|
return self.queryChain(appending: GroupBy<O>(keyPaths))
|
||||||
}
|
}
|
||||||
@@ -751,7 +848,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter clause: the `QueryClause` to add to the `QueryChainBuilder`
|
- parameter clause: the `QueryClause` to add to the `QueryChainBuilder`
|
||||||
- returns: a new `QueryChainBuilder` containing the `QueryClause`
|
- returns: a new `QueryChainBuilder` containing the `QueryClause`
|
||||||
*/
|
*/
|
||||||
public func appending(_ clause: QueryClause) -> QueryChainBuilder<O, R> {
|
public func appending(
|
||||||
|
_ clause: QueryClause
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: clause)
|
return self.queryChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -762,7 +861,9 @@ extension QueryChainBuilder {
|
|||||||
- parameter clauses: the `QueryClause`s to add to the `QueryChainBuilder`
|
- parameter clauses: the `QueryClause`s to add to the `QueryChainBuilder`
|
||||||
- returns: a new `QueryChainBuilder` containing the `QueryClause`s
|
- returns: a new `QueryChainBuilder` containing the `QueryClause`s
|
||||||
*/
|
*/
|
||||||
public func appending<S: Sequence>(contentsOf clauses: S) -> QueryChainBuilder<O, R> where S.Element == QueryClause {
|
public func appending<S: Sequence>(
|
||||||
|
contentsOf clauses: S
|
||||||
|
) -> QueryChainBuilder<O, R> where S.Element == QueryClause {
|
||||||
|
|
||||||
return self.queryChain(appending: clauses)
|
return self.queryChain(appending: clauses)
|
||||||
}
|
}
|
||||||
@@ -770,7 +871,9 @@ extension QueryChainBuilder {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private func queryChain(appending clause: QueryClause) -> QueryChainBuilder<O, R> {
|
private func queryChain(
|
||||||
|
appending clause: QueryClause
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
from: self.from,
|
from: self.from,
|
||||||
@@ -779,7 +882,9 @@ extension QueryChainBuilder {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func queryChain<S: Sequence>(appending clauses: S) -> QueryChainBuilder<O, R> where S.Element == QueryClause {
|
private func queryChain<S: Sequence>(
|
||||||
|
appending clauses: S
|
||||||
|
) -> QueryChainBuilder<O, R> where S.Element == QueryClause {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
from: self.from,
|
from: self.from,
|
||||||
@@ -800,7 +905,9 @@ extension QueryChainBuilder where O: NSManagedObject {
|
|||||||
- parameter keyPath: a key path to group the query results with
|
- parameter keyPath: a key path to group the query results with
|
||||||
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
||||||
*/
|
*/
|
||||||
public func groupBy<T>(_ keyPath: KeyPath<O, T>) -> QueryChainBuilder<O, R> {
|
public func groupBy<T>(
|
||||||
|
_ keyPath: KeyPath<O, T>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.groupBy(GroupBy<O>(keyPath))
|
return self.groupBy(GroupBy<O>(keyPath))
|
||||||
}
|
}
|
||||||
@@ -817,7 +924,9 @@ extension QueryChainBuilder where O: CoreStoreObject {
|
|||||||
- parameter clause: a `Where` clause to add to the query builder
|
- parameter clause: a `Where` clause to add to the query builder
|
||||||
- returns: a new `QueryChainBuilder` containing the `Where` clause
|
- returns: a new `QueryChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`<T: AnyWhereClause>(_ clause: (O) -> T) -> QueryChainBuilder<O, R> {
|
public func `where`<T: AnyWhereClause>(
|
||||||
|
_ clause: (O) -> T
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.queryChain(appending: clause(O.meta))
|
return self.queryChain(appending: clause(O.meta))
|
||||||
}
|
}
|
||||||
@@ -828,7 +937,9 @@ extension QueryChainBuilder where O: CoreStoreObject {
|
|||||||
- parameter keyPath: a key path to group the query results with
|
- parameter keyPath: a key path to group the query results with
|
||||||
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
||||||
*/
|
*/
|
||||||
public func groupBy<T>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<T>>) -> QueryChainBuilder<O, R> {
|
public func groupBy<T>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<T>>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.groupBy(GroupBy<O>(keyPath))
|
return self.groupBy(GroupBy<O>(keyPath))
|
||||||
}
|
}
|
||||||
@@ -839,7 +950,9 @@ extension QueryChainBuilder where O: CoreStoreObject {
|
|||||||
- parameter keyPath: a key path to group the query results with
|
- parameter keyPath: a key path to group the query results with
|
||||||
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
||||||
*/
|
*/
|
||||||
public func groupBy<T>(_ keyPath: KeyPath<O, FieldContainer<O>.Virtual<T>>) -> QueryChainBuilder<O, R> {
|
public func groupBy<T>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Virtual<T>>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.groupBy(GroupBy<O>(keyPath))
|
return self.groupBy(GroupBy<O>(keyPath))
|
||||||
}
|
}
|
||||||
@@ -850,7 +963,9 @@ extension QueryChainBuilder where O: CoreStoreObject {
|
|||||||
- parameter keyPath: a key path to group the query results with
|
- parameter keyPath: a key path to group the query results with
|
||||||
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
- returns: a new `QueryChainBuilder` containing the `GroupBy` clause
|
||||||
*/
|
*/
|
||||||
public func groupBy<T>(_ keyPath: KeyPath<O, FieldContainer<O>.Coded<T>>) -> QueryChainBuilder<O, R> {
|
public func groupBy<T>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Coded<T>>
|
||||||
|
) -> QueryChainBuilder<O, R> {
|
||||||
|
|
||||||
return self.groupBy(GroupBy<O>(keyPath))
|
return self.groupBy(GroupBy<O>(keyPath))
|
||||||
}
|
}
|
||||||
@@ -867,7 +982,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter clause: a `Where` clause to add to the fetch builder
|
- parameter clause: a `Where` clause to add to the fetch builder
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `Where` clause
|
- returns: a new `SectionMonitorChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(_ clause: Where<O>) -> SectionMonitorChainBuilder<O> {
|
public func `where`(
|
||||||
|
_ clause: Where<O>
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: clause)
|
return self.sectionMonitorChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -878,7 +995,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses
|
- returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses
|
||||||
*/
|
*/
|
||||||
public func `where`(combineByAnd clauses: Where<O>...) -> SectionMonitorChainBuilder<O> {
|
public func `where`(
|
||||||
|
combineByAnd clauses: Where<O>...
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: clauses.combinedByAnd())
|
return self.sectionMonitorChain(appending: clauses.combinedByAnd())
|
||||||
}
|
}
|
||||||
@@ -889,7 +1008,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
- parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with
|
||||||
- returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses
|
- returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses
|
||||||
*/
|
*/
|
||||||
public func `where`(combineByOr clauses: Where<O>...) -> SectionMonitorChainBuilder<O> {
|
public func `where`(
|
||||||
|
combineByOr clauses: Where<O>...
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: clauses.combinedByOr())
|
return self.sectionMonitorChain(appending: clauses.combinedByOr())
|
||||||
}
|
}
|
||||||
@@ -901,7 +1022,10 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter args: the arguments for `format`
|
- parameter args: the arguments for `format`
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `Where` clause
|
- returns: a new `SectionMonitorChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(format: String, _ args: Any...) -> SectionMonitorChainBuilder<O> {
|
public func `where`(
|
||||||
|
format: String,
|
||||||
|
_ args: Any...
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: Where<O>(format, argumentArray: args))
|
return self.sectionMonitorChain(appending: Where<O>(format, argumentArray: args))
|
||||||
}
|
}
|
||||||
@@ -913,7 +1037,10 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter argumentArray: the arguments for `format`
|
- parameter argumentArray: the arguments for `format`
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `Where` clause
|
- returns: a new `SectionMonitorChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`(format: String, argumentArray: [Any]?) -> SectionMonitorChainBuilder<O> {
|
public func `where`(
|
||||||
|
format: String,
|
||||||
|
argumentArray: [Any]?
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: Where<O>(format, argumentArray: argumentArray))
|
return self.sectionMonitorChain(appending: Where<O>(format, argumentArray: argumentArray))
|
||||||
}
|
}
|
||||||
@@ -924,7 +1051,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter clause: the `OrderBy` clause to add
|
- parameter clause: the `OrderBy` clause to add
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `OrderBy` clause
|
- returns: a new `SectionMonitorChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ clause: OrderBy<O>) -> SectionMonitorChainBuilder<O> {
|
public func orderBy(
|
||||||
|
_ clause: OrderBy<O>
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: clause)
|
return self.sectionMonitorChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -936,7 +1065,10 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter sortKeys: a series of other `SortKey`s
|
- parameter sortKeys: a series of other `SortKey`s
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `OrderBy` clause
|
- returns: a new `SectionMonitorChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ sortKey: OrderBy<O>.SortKey, _ sortKeys: OrderBy<O>.SortKey...) -> SectionMonitorChainBuilder<O> {
|
public func orderBy(
|
||||||
|
_ sortKey: OrderBy<O>.SortKey,
|
||||||
|
_ sortKeys: OrderBy<O>.SortKey...
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: OrderBy<O>([sortKey] + sortKeys))
|
return self.sectionMonitorChain(appending: OrderBy<O>([sortKey] + sortKeys))
|
||||||
}
|
}
|
||||||
@@ -947,7 +1079,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter sortKeys: a series of `SortKey`s
|
- parameter sortKeys: a series of `SortKey`s
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `OrderBy` clause
|
- returns: a new `SectionMonitorChainBuilder` containing the `OrderBy` clause
|
||||||
*/
|
*/
|
||||||
public func orderBy(_ sortKeys: [OrderBy<O>.SortKey]) -> SectionMonitorChainBuilder<O> {
|
public func orderBy(
|
||||||
|
_ sortKeys: [OrderBy<O>.SortKey]
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: OrderBy<O>(sortKeys))
|
return self.sectionMonitorChain(appending: OrderBy<O>(sortKeys))
|
||||||
}
|
}
|
||||||
@@ -958,7 +1092,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter fetchRequest: the block to customize the `NSFetchRequest`
|
- parameter fetchRequest: the block to customize the `NSFetchRequest`
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `Tweak` clause
|
- returns: a new `SectionMonitorChainBuilder` containing the `Tweak` clause
|
||||||
*/
|
*/
|
||||||
public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> SectionMonitorChainBuilder<O> {
|
public func tweak(
|
||||||
|
_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: Tweak(fetchRequest))
|
return self.sectionMonitorChain(appending: Tweak(fetchRequest))
|
||||||
}
|
}
|
||||||
@@ -969,7 +1105,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter clause: the `QueryClause` to add to the `SectionMonitorChainBuilder`
|
- parameter clause: the `QueryClause` to add to the `SectionMonitorChainBuilder`
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `QueryClause`
|
- returns: a new `SectionMonitorChainBuilder` containing the `QueryClause`
|
||||||
*/
|
*/
|
||||||
public func appending(_ clause: FetchClause) -> SectionMonitorChainBuilder<O> {
|
public func appending(
|
||||||
|
_ clause: FetchClause
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: clause)
|
return self.sectionMonitorChain(appending: clause)
|
||||||
}
|
}
|
||||||
@@ -980,7 +1118,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
- parameter clauses: the `QueryClause`s to add to the `SectionMonitorChainBuilder`
|
- parameter clauses: the `QueryClause`s to add to the `SectionMonitorChainBuilder`
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `QueryClause`s
|
- returns: a new `SectionMonitorChainBuilder` containing the `QueryClause`s
|
||||||
*/
|
*/
|
||||||
public func appending<S: Sequence>(contentsOf clauses: S) -> SectionMonitorChainBuilder<O> where S.Element == FetchClause {
|
public func appending<S: Sequence>(
|
||||||
|
contentsOf clauses: S
|
||||||
|
) -> SectionMonitorChainBuilder<O> where S.Element == FetchClause {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: clauses)
|
return self.sectionMonitorChain(appending: clauses)
|
||||||
}
|
}
|
||||||
@@ -988,7 +1128,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private func sectionMonitorChain(appending clause: FetchClause) -> SectionMonitorChainBuilder<O> {
|
private func sectionMonitorChain(
|
||||||
|
appending clause: FetchClause
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
from: self.from,
|
from: self.from,
|
||||||
@@ -997,7 +1139,9 @@ extension SectionMonitorChainBuilder {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func sectionMonitorChain<S: Sequence>(appending clauses: S) -> SectionMonitorChainBuilder<O> where S.Element == FetchClause {
|
private func sectionMonitorChain<S: Sequence>(
|
||||||
|
appending clauses: S
|
||||||
|
) -> SectionMonitorChainBuilder<O> where S.Element == FetchClause {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
from: self.from,
|
from: self.from,
|
||||||
@@ -1018,7 +1162,9 @@ extension SectionMonitorChainBuilder where O: CoreStoreObject {
|
|||||||
- parameter clause: a `Where` clause to add to the fetch builder
|
- parameter clause: a `Where` clause to add to the fetch builder
|
||||||
- returns: a new `SectionMonitorChainBuilder` containing the `Where` clause
|
- returns: a new `SectionMonitorChainBuilder` containing the `Where` clause
|
||||||
*/
|
*/
|
||||||
public func `where`<T: AnyWhereClause>(_ clause: (O) -> T) -> SectionMonitorChainBuilder<O> {
|
public func `where`<T: AnyWhereClause>(
|
||||||
|
_ clause: (O) -> T
|
||||||
|
) -> SectionMonitorChainBuilder<O> {
|
||||||
|
|
||||||
return self.sectionMonitorChain(appending: clause(O.meta))
|
return self.sectionMonitorChain(appending: clause(O.meta))
|
||||||
}
|
}
|
||||||
|
|||||||
+64
-20
@@ -60,7 +60,10 @@ public struct From<O: DynamicObject> {
|
|||||||
*/
|
*/
|
||||||
public init() {
|
public init() {
|
||||||
|
|
||||||
self.init(entityClass: O.self, configurations: nil)
|
self.init(
|
||||||
|
entityClass: O.self,
|
||||||
|
configurations: nil
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,9 +73,14 @@ public struct From<O: DynamicObject> {
|
|||||||
```
|
```
|
||||||
- parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type
|
- parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type
|
||||||
*/
|
*/
|
||||||
public init(_ entity: O.Type) {
|
public init(
|
||||||
|
_ entity: O.Type
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(entityClass: entity, configurations: nil)
|
self.init(
|
||||||
|
entityClass: entity,
|
||||||
|
configurations: nil
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,9 +91,15 @@ public struct From<O: DynamicObject> {
|
|||||||
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
||||||
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
||||||
*/
|
*/
|
||||||
public init(_ configuration: ModelConfiguration, _ otherConfigurations: ModelConfiguration...) {
|
public init(
|
||||||
|
_ configuration: ModelConfiguration,
|
||||||
|
_ otherConfigurations: ModelConfiguration...
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(entityClass: O.self, configurations: [configuration] + otherConfigurations)
|
self.init(
|
||||||
|
entityClass: O.self,
|
||||||
|
configurations: [configuration] + otherConfigurations
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,9 +109,14 @@ public struct From<O: DynamicObject> {
|
|||||||
```
|
```
|
||||||
- parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
- parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
||||||
*/
|
*/
|
||||||
public init(_ configurations: [ModelConfiguration]) {
|
public init(
|
||||||
|
_ configurations: [ModelConfiguration]
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(entityClass: O.self, configurations: configurations)
|
self.init(
|
||||||
|
entityClass: O.self,
|
||||||
|
configurations: configurations
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,9 +128,16 @@ public struct From<O: DynamicObject> {
|
|||||||
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
||||||
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
||||||
*/
|
*/
|
||||||
public init(_ entity: O.Type, _ configuration: ModelConfiguration, _ otherConfigurations: ModelConfiguration...) {
|
public init(
|
||||||
|
_ entity: O.Type,
|
||||||
|
_ configuration: ModelConfiguration,
|
||||||
|
_ otherConfigurations: ModelConfiguration...
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(entityClass: entity, configurations: [configuration] + otherConfigurations)
|
self.init(
|
||||||
|
entityClass: entity,
|
||||||
|
configurations: [configuration] + otherConfigurations
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,9 +148,15 @@ public struct From<O: DynamicObject> {
|
|||||||
- parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type
|
- parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type
|
||||||
- parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
- parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
||||||
*/
|
*/
|
||||||
public init(_ entity: O.Type, _ configurations: [ModelConfiguration]) {
|
public init(
|
||||||
|
_ entity: O.Type,
|
||||||
|
_ configurations: [ModelConfiguration]
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(entityClass: entity, configurations: configurations)
|
self.init(
|
||||||
|
entityClass: entity,
|
||||||
|
configurations: configurations
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,14 +164,24 @@ public struct From<O: DynamicObject> {
|
|||||||
|
|
||||||
internal let findPersistentStores: (_ context: NSManagedObjectContext) -> [NSPersistentStore]?
|
internal let findPersistentStores: (_ context: NSManagedObjectContext) -> [NSPersistentStore]?
|
||||||
|
|
||||||
internal init(entityClass: O.Type, configurations: [ModelConfiguration]?, findPersistentStores: @escaping (_ context: NSManagedObjectContext) -> [NSPersistentStore]?) {
|
internal init(
|
||||||
|
entityClass: O.Type,
|
||||||
|
configurations: [ModelConfiguration]?,
|
||||||
|
findPersistentStores: @escaping (
|
||||||
|
_ context: NSManagedObjectContext
|
||||||
|
) -> [NSPersistentStore]?
|
||||||
|
) {
|
||||||
|
|
||||||
self.entityClass = entityClass
|
self.entityClass = entityClass
|
||||||
self.configurations = configurations
|
self.configurations = configurations
|
||||||
self.findPersistentStores = findPersistentStores
|
self.findPersistentStores = findPersistentStores
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func applyToFetchRequest<U>(_ fetchRequest: Internals.CoreStoreFetchRequest<U>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) throws {
|
internal func applyToFetchRequest<U>(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<U>,
|
||||||
|
context: NSManagedObjectContext,
|
||||||
|
applyAffectedStores: Bool = true
|
||||||
|
) throws(CoreStoreError) {
|
||||||
|
|
||||||
guard let parentStack = context.parentStack else {
|
guard let parentStack = context.parentStack else {
|
||||||
|
|
||||||
@@ -158,7 +200,7 @@ public struct From<O: DynamicObject> {
|
|||||||
|
|
||||||
try self.applyAffectedStoresForFetchedRequest(fetchRequest, context: context)
|
try self.applyAffectedStoresForFetchedRequest(fetchRequest, context: context)
|
||||||
}
|
}
|
||||||
catch let error as CoreStoreError {
|
catch {
|
||||||
|
|
||||||
Internals.log(
|
Internals.log(
|
||||||
error,
|
error,
|
||||||
@@ -166,13 +208,12 @@ public struct From<O: DynamicObject> {
|
|||||||
)
|
)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
catch {
|
|
||||||
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func applyAffectedStoresForFetchedRequest<U>(_ fetchRequest: Internals.CoreStoreFetchRequest<U>, context: NSManagedObjectContext) throws {
|
internal func applyAffectedStoresForFetchedRequest<U>(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<U>,
|
||||||
|
context: NSManagedObjectContext
|
||||||
|
) throws(CoreStoreError) {
|
||||||
|
|
||||||
let stores = self.findPersistentStores(context)
|
let stores = self.findPersistentStores(context)
|
||||||
fetchRequest.affectedStores = stores
|
fetchRequest.affectedStores = stores
|
||||||
@@ -186,7 +227,10 @@ public struct From<O: DynamicObject> {
|
|||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private init(entityClass: O.Type, configurations: [ModelConfiguration]?) {
|
private init(
|
||||||
|
entityClass: O.Type,
|
||||||
|
configurations: [ModelConfiguration]?
|
||||||
|
) {
|
||||||
|
|
||||||
self.entityClass = entityClass
|
self.entityClass = entityClass
|
||||||
self.configurations = configurations
|
self.configurations = configurations
|
||||||
|
|||||||
@@ -66,7 +66,10 @@ public protocol ImportableObject: DynamicObject {
|
|||||||
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
||||||
- returns: `true` if an object should be created from `source`. Return `false` to ignore.
|
- returns: `true` if an object should be created from `source`. Return `false` to ignore.
|
||||||
*/
|
*/
|
||||||
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool
|
static func shouldInsert(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) -> Bool
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Implements the actual importing of data from `source`. Implementers should pull values from `source` and assign them to the receiver's attributes. Note that throwing from this method will cause subsequent imports that are part of the same `importObjects(:sourceArray:)` call to be cancelled.
|
Implements the actual importing of data from `source`. Implementers should pull values from `source` and assign them to the receiver's attributes. Note that throwing from this method will cause subsequent imports that are part of the same `importObjects(:sourceArray:)` call to be cancelled.
|
||||||
@@ -74,7 +77,10 @@ public protocol ImportableObject: DynamicObject {
|
|||||||
- parameter source: the object to import from
|
- parameter source: the object to import from
|
||||||
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
||||||
*/
|
*/
|
||||||
func didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throws
|
func didInsert(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) throws(any Swift.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -82,7 +88,10 @@ public protocol ImportableObject: DynamicObject {
|
|||||||
|
|
||||||
extension ImportableObject {
|
extension ImportableObject {
|
||||||
|
|
||||||
public static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool {
|
public static func shouldInsert(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,10 @@ public protocol ImportableUniqueObject: ImportableObject, Hashable {
|
|||||||
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
||||||
- returns: `true` if an object should be created from `source`. Return `false` to ignore.
|
- returns: `true` if an object should be created from `source`. Return `false` to ignore.
|
||||||
*/
|
*/
|
||||||
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool
|
static func shouldInsert(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) -> Bool
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return `true` if an object should be updated from `source`. Return `false` to ignore and skip `source`. The default implementation returns `true`.
|
Return `true` if an object should be updated from `source`. Return `false` to ignore and skip `source`. The default implementation returns `true`.
|
||||||
@@ -87,7 +90,10 @@ public protocol ImportableUniqueObject: ImportableObject, Hashable {
|
|||||||
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
||||||
- returns: `true` if an object should be updated from `source`. Return `false` to ignore.
|
- returns: `true` if an object should be updated from `source`. Return `false` to ignore.
|
||||||
*/
|
*/
|
||||||
static func shouldUpdate(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool
|
static func shouldUpdate(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) -> Bool
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return the unique ID as extracted from `source`. This method is called before `shouldInsert(from:in:)` or `shouldUpdate(from:in:)`. Return `nil` to skip importing from `source`. Note that throwing from this method will cause subsequent imports that are part of the same `importUniqueObjects(:sourceArray:)` call to be cancelled.
|
Return the unique ID as extracted from `source`. This method is called before `shouldInsert(from:in:)` or `shouldUpdate(from:in:)`. Return `nil` to skip importing from `source`. Note that throwing from this method will cause subsequent imports that are part of the same `importUniqueObjects(:sourceArray:)` call to be cancelled.
|
||||||
@@ -96,7 +102,10 @@ public protocol ImportableUniqueObject: ImportableObject, Hashable {
|
|||||||
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
||||||
- returns: the unique ID as extracted from `source`, or `nil` to skip importing from `source`.
|
- returns: the unique ID as extracted from `source`, or `nil` to skip importing from `source`.
|
||||||
*/
|
*/
|
||||||
static func uniqueID(from source: ImportSource, in transaction: BaseDataTransaction) throws -> UniqueIDType?
|
static func uniqueID(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) throws(any Swift.Error) -> UniqueIDType?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Implements the actual importing of data from `source`. This method is called just after the object is created and assigned its unique ID as returned from `uniqueID(from:in:)`. Implementers should pull values from `source` and assign them to the receiver's attributes. Note that throwing from this method will cause subsequent imports that are part of the same `importUniqueObjects(:sourceArray:)` call to be cancelled. The default implementation simply calls `update(from:in:)`.
|
Implements the actual importing of data from `source`. This method is called just after the object is created and assigned its unique ID as returned from `uniqueID(from:in:)`. Implementers should pull values from `source` and assign them to the receiver's attributes. Note that throwing from this method will cause subsequent imports that are part of the same `importUniqueObjects(:sourceArray:)` call to be cancelled. The default implementation simply calls `update(from:in:)`.
|
||||||
@@ -104,7 +113,10 @@ public protocol ImportableUniqueObject: ImportableObject, Hashable {
|
|||||||
- parameter source: the object to import from
|
- parameter source: the object to import from
|
||||||
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
||||||
*/
|
*/
|
||||||
func didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throws
|
func didInsert(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) throws(any Swift.Error)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Implements the actual importing of data from `source`. This method is called just after the existing object is fetched using its unique ID. Implementers should pull values from `source` and assign them to the receiver's attributes. Note that throwing from this method will cause subsequent imports that are part of the same `importUniqueObjects(:sourceArray:)` call to be cancelled.
|
Implements the actual importing of data from `source`. This method is called just after the existing object is fetched using its unique ID. Implementers should pull values from `source` and assign them to the receiver's attributes. Note that throwing from this method will cause subsequent imports that are part of the same `importUniqueObjects(:sourceArray:)` call to be cancelled.
|
||||||
@@ -112,7 +124,10 @@ public protocol ImportableUniqueObject: ImportableObject, Hashable {
|
|||||||
- parameter source: the object to import from
|
- parameter source: the object to import from
|
||||||
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
||||||
*/
|
*/
|
||||||
func update(from source: ImportSource, in transaction: BaseDataTransaction) throws
|
func update(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) throws(any Swift.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -146,17 +161,26 @@ extension ImportableUniqueObject where UniqueIDType.QueryableNativeType: CoreDat
|
|||||||
|
|
||||||
extension ImportableUniqueObject {
|
extension ImportableUniqueObject {
|
||||||
|
|
||||||
public static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool {
|
public static func shouldInsert(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
return Self.shouldUpdate(from: source, in: transaction)
|
return Self.shouldUpdate(from: source, in: transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func shouldUpdate(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool{
|
public static func shouldUpdate(
|
||||||
|
from source: ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func didInsert(from source: Self.ImportSource, in transaction: BaseDataTransaction) throws {
|
public func didInsert(
|
||||||
|
from source: Self.ImportSource,
|
||||||
|
in transaction: BaseDataTransaction
|
||||||
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
try self.update(from: source, in: transaction)
|
try self.update(from: source, in: transaction)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,14 @@ public final class InferredSchemaMappingProvider: Hashable, SchemaMappingProvide
|
|||||||
|
|
||||||
// MARK: SchemaMappingProvider
|
// MARK: SchemaMappingProvider
|
||||||
|
|
||||||
public func cs_createMappingModel(from sourceSchema: DynamicSchema, to destinationSchema: DynamicSchema, storage: LocalStorage) throws -> (mappingModel: NSMappingModel, migrationType: MigrationType) {
|
public func cs_createMappingModel(
|
||||||
|
from sourceSchema: DynamicSchema,
|
||||||
|
to destinationSchema: DynamicSchema,
|
||||||
|
storage: LocalStorage
|
||||||
|
) throws(CoreStoreError) -> (
|
||||||
|
mappingModel: NSMappingModel,
|
||||||
|
migrationType: MigrationType
|
||||||
|
) {
|
||||||
|
|
||||||
let sourceModel = sourceSchema.rawModel()
|
let sourceModel = sourceSchema.rawModel()
|
||||||
let destinationModel = destinationSchema.rawModel()
|
let destinationModel = destinationSchema.rawModel()
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func performFetchFromSpecifiedStores() throws {
|
internal func performFetchFromSpecifiedStores() throws(any Swift.Error) {
|
||||||
|
|
||||||
try self.reapplyAffectedStores(self.typedFetchRequest, self.managedObjectContext)
|
try self.reapplyAffectedStores(self.typedFetchRequest, self.managedObjectContext)
|
||||||
try self.performFetch()
|
try self.performFetch()
|
||||||
@@ -103,6 +103,9 @@ extension Internals {
|
|||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
private let reapplyAffectedStores: (_ fetchRequest: Internals.CoreStoreFetchRequest<NSManagedObject>, _ context: NSManagedObjectContext) throws -> Void
|
private let reapplyAffectedStores: (
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<NSManagedObject>,
|
||||||
|
_ context: NSManagedObjectContext
|
||||||
|
) throws(any Swift.Error) -> Void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,11 +106,11 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(watchOS)
|
#if os(watchOS) || !canImport(QuartzCore)
|
||||||
|
|
||||||
performDiffingUpdates()
|
performDiffingUpdates()
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
CATransaction.begin()
|
CATransaction.begin()
|
||||||
|
|
||||||
@@ -122,8 +122,7 @@ extension Internals {
|
|||||||
|
|
||||||
CATransaction.commit()
|
CATransaction.commit()
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,11 +91,14 @@ extension Internals {
|
|||||||
// MARK: NSFetchedResultsControllerDelegate
|
// MARK: NSFetchedResultsControllerDelegate
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
dynamic func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
|
dynamic func controllerDidChangeContent(
|
||||||
|
_ controller: NSFetchedResultsController<NSFetchRequestResult>
|
||||||
|
) {
|
||||||
|
|
||||||
var snapshot = Internals.DiffableDataSourceSnapshot(
|
var snapshot = Internals.DiffableDataSourceSnapshot(
|
||||||
sections: controller.sections ?? [],
|
sections: controller.sections ?? [],
|
||||||
sectionIndexTransformer: self.handler.map({ $0.sectionIndexTransformer }) ?? { _ in nil },
|
sectionIndexTransformer: self.handler
|
||||||
|
.map({ $0.sectionIndexTransformer }) ?? { _ in nil },
|
||||||
fetchOffset: controller.fetchRequest.fetchOffset,
|
fetchOffset: controller.fetchRequest.fetchOffset,
|
||||||
fetchLimit: controller.fetchRequest.fetchLimit
|
fetchLimit: controller.fetchRequest.fetchLimit
|
||||||
)
|
)
|
||||||
@@ -117,13 +120,24 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
dynamic func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
|
dynamic func controller(
|
||||||
|
_ controller: NSFetchedResultsController<NSFetchRequestResult>,
|
||||||
|
didChange anObject: Any,
|
||||||
|
at indexPath: IndexPath?,
|
||||||
|
for type: NSFetchedResultsChangeType,
|
||||||
|
newIndexPath: IndexPath?
|
||||||
|
) {
|
||||||
|
|
||||||
let object = anObject as! NSManagedObject
|
let object = anObject as! NSManagedObject
|
||||||
self.reloadedItemIDs.append(object.objectID)
|
self.reloadedItemIDs.append(object.objectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
|
func controller(
|
||||||
|
_ controller: NSFetchedResultsController<NSFetchRequestResult>,
|
||||||
|
didChange sectionInfo: NSFetchedResultsSectionInfo,
|
||||||
|
atSectionIndex sectionIndex: Int,
|
||||||
|
for type: NSFetchedResultsChangeType
|
||||||
|
) {
|
||||||
|
|
||||||
self.reloadedSectionIDs.append(sectionInfo.name)
|
self.reloadedSectionIDs.append(sectionInfo.name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,9 @@ extension Internals {
|
|||||||
// MARK: NSFetchedResultsControllerDelegate
|
// MARK: NSFetchedResultsControllerDelegate
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
dynamic func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
|
dynamic func controllerWillChangeContent(
|
||||||
|
_ controller: NSFetchedResultsController<NSFetchRequestResult>
|
||||||
|
) {
|
||||||
|
|
||||||
self.taskGroup.enter()
|
self.taskGroup.enter()
|
||||||
guard self.enabled else {
|
guard self.enabled else {
|
||||||
@@ -107,7 +109,9 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
dynamic func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
|
dynamic func controllerDidChangeContent(
|
||||||
|
_ controller: NSFetchedResultsController<NSFetchRequestResult>
|
||||||
|
) {
|
||||||
|
|
||||||
defer {
|
defer {
|
||||||
|
|
||||||
@@ -121,7 +125,13 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
dynamic func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
|
dynamic func controller(
|
||||||
|
_ controller: NSFetchedResultsController<NSFetchRequestResult>,
|
||||||
|
didChange anObject: Any,
|
||||||
|
at indexPath: IndexPath?,
|
||||||
|
for type: NSFetchedResultsChangeType,
|
||||||
|
newIndexPath: IndexPath?
|
||||||
|
) {
|
||||||
|
|
||||||
guard self.enabled else {
|
guard self.enabled else {
|
||||||
|
|
||||||
@@ -137,7 +147,12 @@ extension Internals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
dynamic func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
|
dynamic func controller(
|
||||||
|
_ controller: NSFetchedResultsController<NSFetchRequestResult>,
|
||||||
|
didChange sectionInfo: NSFetchedResultsSectionInfo,
|
||||||
|
atSectionIndex sectionIndex: Int,
|
||||||
|
for type: NSFetchedResultsChangeType
|
||||||
|
) {
|
||||||
|
|
||||||
guard self.enabled else {
|
guard self.enabled else {
|
||||||
|
|
||||||
|
|||||||
@@ -55,11 +55,18 @@ extension Internals {
|
|||||||
|
|
||||||
// MARK: NSMigrationManager
|
// MARK: NSMigrationManager
|
||||||
|
|
||||||
init(sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel, progress: Progress) {
|
init(
|
||||||
|
sourceModel: NSManagedObjectModel,
|
||||||
|
destinationModel: NSManagedObjectModel,
|
||||||
|
progress: Progress
|
||||||
|
) {
|
||||||
|
|
||||||
self.progress = progress
|
self.progress = progress
|
||||||
|
|
||||||
super.init(sourceModel: sourceModel, destinationModel: destinationModel)
|
super.init(
|
||||||
|
sourceModel: sourceModel,
|
||||||
|
destinationModel: destinationModel
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,12 @@ extension Internals {
|
|||||||
|
|
||||||
let observer: NSObjectProtocol
|
let observer: NSObjectProtocol
|
||||||
|
|
||||||
init(notificationName: Notification.Name, object: Any?, queue: OperationQueue? = nil, closure: @escaping (_ note: Notification) -> Void) {
|
init(
|
||||||
|
notificationName: Notification.Name,
|
||||||
|
object: Any?,
|
||||||
|
queue: OperationQueue? = nil,
|
||||||
|
closure: @escaping (_ note: Notification) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.observer = NotificationCenter.default.addObserver(
|
self.observer = NotificationCenter.default.addObserver(
|
||||||
forName: notificationName,
|
forName: notificationName,
|
||||||
|
|||||||
@@ -35,7 +35,12 @@ extension Internals {
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal init(notificationName: Notification.Name, object: Any?, queue: OperationQueue? = nil, sharedValue: @escaping (_ note: Notification) -> T) {
|
internal init(
|
||||||
|
notificationName: Notification.Name,
|
||||||
|
object: Any?,
|
||||||
|
queue: OperationQueue? = nil,
|
||||||
|
sharedValue: @escaping (_ note: Notification) -> T
|
||||||
|
) {
|
||||||
|
|
||||||
self.observer = NotificationCenter.default.addObserver(
|
self.observer = NotificationCenter.default.addObserver(
|
||||||
forName: notificationName,
|
forName: notificationName,
|
||||||
@@ -59,9 +64,15 @@ extension Internals {
|
|||||||
self.observers.removeAllObjects()
|
self.observers.removeAllObjects()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func addObserver<U: AnyObject>(_ observer: U, closure: @escaping (T) -> Void) {
|
internal func addObserver<U: AnyObject>(
|
||||||
|
_ observer: U,
|
||||||
|
closure: @escaping (T) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.observers.setObject(Closure<T, Void>(closure), forKey: observer)
|
self.observers.setObject(
|
||||||
|
Closure<T, Void>(closure),
|
||||||
|
forKey: observer
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func removeObserver<U: AnyObject>(_ observer: U) {
|
internal func removeObserver<U: AnyObject>(_ observer: U) {
|
||||||
|
|||||||
+43
-2
@@ -39,8 +39,6 @@ internal enum Internals {
|
|||||||
return object_getClass(instance) as! T.Type
|
return object_getClass(instance) as! T.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Associated Objects
|
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
internal static func getAssociatedObjectForKey<T: AnyObject>(_ key: UnsafeRawPointer, inObject object: Any) -> T? {
|
internal static func getAssociatedObjectForKey<T: AnyObject>(_ key: UnsafeRawPointer, inObject object: Any) -> T? {
|
||||||
|
|
||||||
@@ -123,4 +121,47 @@ internal enum Internals {
|
|||||||
|
|
||||||
return closure()
|
return closure()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@inline(__always)
|
||||||
|
internal static func autoreleasepool<T>(
|
||||||
|
_ closure: () -> T
|
||||||
|
) -> T {
|
||||||
|
|
||||||
|
return ObjectiveC.autoreleasepool(invoking: closure)
|
||||||
|
}
|
||||||
|
|
||||||
|
@inline(__always)
|
||||||
|
internal static func autoreleasepool<T>(
|
||||||
|
_ closure: () throws(any Swift.Error) -> T
|
||||||
|
) throws(any Swift.Error) -> T {
|
||||||
|
|
||||||
|
return try ObjectiveC.autoreleasepool(invoking: closure)
|
||||||
|
}
|
||||||
|
|
||||||
|
@inline(__always)
|
||||||
|
internal static func autoreleasepool<T>(
|
||||||
|
_ closure: () throws(CoreStoreError) -> T
|
||||||
|
) throws(CoreStoreError) -> T {
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
return try ObjectiveC.autoreleasepool(invoking: closure)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
|
||||||
|
throw CoreStoreError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@inline(__always)
|
||||||
|
internal static func withCheckedThrowingContinuation<T>(
|
||||||
|
function: String = #function,
|
||||||
|
_ body: (CheckedContinuation<T, any Swift.Error>) -> Void
|
||||||
|
) async throws(any Swift.Error) -> T {
|
||||||
|
|
||||||
|
return try await _Concurrency.withCheckedThrowingContinuation(
|
||||||
|
function: function,
|
||||||
|
body
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-8
@@ -60,7 +60,11 @@ public struct Into<O: DynamicObject>: Hashable {
|
|||||||
*/
|
*/
|
||||||
public init() {
|
public init() {
|
||||||
|
|
||||||
self.init(entityClass: O.self, configuration: nil, inferStoreIfPossible: true)
|
self.init(
|
||||||
|
entityClass: O.self,
|
||||||
|
configuration: nil,
|
||||||
|
inferStoreIfPossible: true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,9 +74,15 @@ public struct Into<O: DynamicObject>: Hashable {
|
|||||||
```
|
```
|
||||||
- parameter entity: the `NSManagedObject` or `CoreStoreObject` type to be created
|
- parameter entity: the `NSManagedObject` or `CoreStoreObject` type to be created
|
||||||
*/
|
*/
|
||||||
public init(_ entity: O.Type) {
|
public init(
|
||||||
|
_ entity: O.Type
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(entityClass: entity, configuration: nil, inferStoreIfPossible: true)
|
self.init(
|
||||||
|
entityClass: entity,
|
||||||
|
configuration: nil,
|
||||||
|
inferStoreIfPossible: true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,9 +92,15 @@ public struct Into<O: DynamicObject>: Hashable {
|
|||||||
```
|
```
|
||||||
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
||||||
*/
|
*/
|
||||||
public init(_ configuration: ModelConfiguration) {
|
public init(
|
||||||
|
_ configuration: ModelConfiguration
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(entityClass: O.self, configuration: configuration, inferStoreIfPossible: false)
|
self.init(
|
||||||
|
entityClass: O.self,
|
||||||
|
configuration: configuration,
|
||||||
|
inferStoreIfPossible: false
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,9 +111,16 @@ public struct Into<O: DynamicObject>: Hashable {
|
|||||||
- parameter entity: the `NSManagedObject` or `CoreStoreObject` type to be created
|
- parameter entity: the `NSManagedObject` or `CoreStoreObject` type to be created
|
||||||
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
|
||||||
*/
|
*/
|
||||||
public init(_ entity: O.Type, _ configuration: ModelConfiguration) {
|
public init(
|
||||||
|
_ entity: O.Type,
|
||||||
|
_ configuration: ModelConfiguration
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(entityClass: entity, configuration: configuration, inferStoreIfPossible: false)
|
self.init(
|
||||||
|
entityClass: entity,
|
||||||
|
configuration: configuration,
|
||||||
|
inferStoreIfPossible: false
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,7 +148,11 @@ public struct Into<O: DynamicObject>: Hashable {
|
|||||||
|
|
||||||
internal let inferStoreIfPossible: Bool
|
internal let inferStoreIfPossible: Bool
|
||||||
|
|
||||||
internal init(entityClass: O.Type, configuration: ModelConfiguration, inferStoreIfPossible: Bool) {
|
internal init(
|
||||||
|
entityClass: O.Type,
|
||||||
|
configuration: ModelConfiguration,
|
||||||
|
inferStoreIfPossible: Bool
|
||||||
|
) {
|
||||||
|
|
||||||
self.entityClass = entityClass
|
self.entityClass = entityClass
|
||||||
self.configuration = configuration
|
self.configuration = configuration
|
||||||
|
|||||||
+400
-96
@@ -35,9 +35,15 @@ import Foundation
|
|||||||
let person = dataStack.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> {
|
public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: value)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,9 +52,15 @@ public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
|||||||
let person = dataStack.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> {
|
public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: value)
|
return !Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,9 +69,15 @@ public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
|||||||
let dog = dataStack.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 {
|
public func ~= <O: NSManagedObject, V: QueryableAttributeType & Equatable, S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ keyPath: KeyPath<O, V>
|
||||||
|
) -> Where<O> where S.Iterator.Element == V {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isMemberOf: sequence)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -71,9 +89,15 @@ public func ~= <O: NSManagedObject, V: QueryableAttributeType & Equatable, S: Se
|
|||||||
let person = dataStack.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> {
|
public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<V>>,
|
||||||
|
_ value: V?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: value)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,9 +106,15 @@ public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
|||||||
let person = dataStack.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> {
|
public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<V>>,
|
||||||
|
_ value: V?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: value)
|
return !Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,9 +123,15 @@ public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
|||||||
let dog = dataStack.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 {
|
public func ~= <O: NSManagedObject, V: QueryableAttributeType & Equatable, S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ keyPath: KeyPath<O, Optional<V>>
|
||||||
|
) -> Where<O> where S.Iterator.Element == V {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isMemberOf: sequence)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,9 +143,16 @@ public func ~= <O: NSManagedObject, V: QueryableAttributeType & Equatable, S: Se
|
|||||||
let person = dataStack.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> {
|
public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>("%K < %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType())
|
return Where<O>(
|
||||||
|
"%K < %@",
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
value.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,9 +161,16 @@ public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
|||||||
let person = dataStack.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> {
|
public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>("%K > %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType())
|
return Where<O>(
|
||||||
|
"%K > %@",
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
value.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,9 +179,16 @@ public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
|||||||
let person = dataStack.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> {
|
public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>("%K <= %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType())
|
return Where<O>(
|
||||||
|
"%K <= %@",
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
value.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,9 +197,16 @@ public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
|||||||
let person = dataStack.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> {
|
public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>("%K >= %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType())
|
return Where<O>(
|
||||||
|
"%K >= %@",
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
value.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -154,15 +218,25 @@ public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
|||||||
let person = dataStack.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> {
|
public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<V>>,
|
||||||
|
_ value: V?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
if let value = value {
|
if let value = value {
|
||||||
|
|
||||||
return Where<O>("%K < %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType())
|
return Where<O>(
|
||||||
|
"%K < %@",
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
value.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
return Where<O>("%K < nil", keyPath._kvcKeyPathString!)
|
return Where<O>(
|
||||||
|
"%K < nil",
|
||||||
|
keyPath._kvcKeyPathString!
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,15 +246,25 @@ public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
|||||||
let person = dataStack.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> {
|
public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<V>>,
|
||||||
|
_ value: V?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
if let value = value {
|
if let value = value {
|
||||||
|
|
||||||
return Where<O>("%K > %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType())
|
return Where<O>(
|
||||||
|
"%K > %@",
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
value.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
return Where<O>("%K > nil", keyPath._kvcKeyPathString!)
|
return Where<O>(
|
||||||
|
"%K > nil",
|
||||||
|
keyPath._kvcKeyPathString!
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,15 +274,25 @@ public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
|||||||
let person = dataStack.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> {
|
public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<V>>,
|
||||||
|
_ value: V?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
if let value = value {
|
if let value = value {
|
||||||
|
|
||||||
return Where<O>("%K <= %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType())
|
return Where<O>(
|
||||||
|
"%K <= %@",
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
value.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
return Where<O>("%K <= nil", keyPath._kvcKeyPathString!)
|
return Where<O>(
|
||||||
|
"%K <= nil",
|
||||||
|
keyPath._kvcKeyPathString!
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,15 +302,25 @@ public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
|||||||
let person = dataStack.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> {
|
public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<V>>,
|
||||||
|
_ value: V?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
if let value = value {
|
if let value = value {
|
||||||
|
|
||||||
return Where<O>("%K >= %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType())
|
return Where<O>(
|
||||||
|
"%K >= %@",
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
value.cs_toQueryableNativeType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
return Where<O>("%K >= nil", keyPath._kvcKeyPathString!)
|
return Where<O>(
|
||||||
|
"%K >= nil",
|
||||||
|
keyPath._kvcKeyPathString!
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,9 +333,15 @@ public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
|||||||
let dog = dataStack.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> {
|
public func == <O: NSManagedObject, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
_ object: D
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: object
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -240,9 +350,15 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
|||||||
let dog = dataStack.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> {
|
public func != <O: NSManagedObject, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
_ object: D
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
return !Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: object
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,9 +367,15 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
|||||||
let dog = dataStack.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 {
|
public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ keyPath: KeyPath<O, D>
|
||||||
|
) -> Where<O> where S.Iterator.Element == D {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isMemberOf: sequence)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,9 +384,15 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
|
|||||||
let dog = dataStack.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> {
|
public func == <O: NSManagedObject, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: objectID
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -273,9 +401,15 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func == <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<O, D>, _ object: O) -> Where<O> where O.ObjectType: NSManagedObject {
|
public func == <O: ObjectRepresentation, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
_ object: O
|
||||||
|
) -> Where<O> where O.ObjectType: NSManagedObject {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object.cs_id())
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: object.cs_id()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -284,9 +418,15 @@ public func == <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<
|
|||||||
let dog = dataStack.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> {
|
public func != <O: NSManagedObject, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
return !Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: objectID
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -295,9 +435,15 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func != <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<O, D>, _ object: O) -> Where<O> where O.ObjectType: NSManagedObject {
|
public func != <O: ObjectRepresentation, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
_ object: O
|
||||||
|
) -> Where<O> where O.ObjectType: NSManagedObject {
|
||||||
|
|
||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object.cs_id())
|
return !Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: object.cs_id()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -306,9 +452,15 @@ public func != <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<
|
|||||||
let dog = dataStack.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 {
|
public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ keyPath: KeyPath<O, D>
|
||||||
|
) -> Where<O> where S.Iterator.Element == NSManagedObjectID {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isMemberOf: sequence)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -320,9 +472,15 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
|
|||||||
let dog = dataStack.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> {
|
public func == <O: NSManagedObject, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<D>>,
|
||||||
|
_ object: D?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: object
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -331,9 +489,15 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func == <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ object: O?) -> Where<O> where O.ObjectType: NSManagedObject {
|
public func == <O: ObjectRepresentation, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<D>>,
|
||||||
|
_ object: O?
|
||||||
|
) -> Where<O> where O.ObjectType: NSManagedObject {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object?.cs_toRaw())
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: object?.cs_toRaw()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -342,9 +506,15 @@ public func == <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<
|
|||||||
let dog = dataStack.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> {
|
public func != <O: NSManagedObject, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<D>>,
|
||||||
|
_ object: D?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
return !Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: object
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -353,9 +523,15 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func != <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ object: O?) -> Where<O> where O.ObjectType: NSManagedObject {
|
public func != <O: ObjectRepresentation, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<D>>,
|
||||||
|
_ object: O?
|
||||||
|
) -> Where<O> where O.ObjectType: NSManagedObject {
|
||||||
|
|
||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object?.cs_toRaw())
|
return !Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: object?.cs_toRaw()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -364,9 +540,15 @@ public func != <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<
|
|||||||
let dog = dataStack.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 {
|
public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ keyPath: KeyPath<O, Optional<D>>
|
||||||
|
) -> Where<O> where S.Iterator.Element == D {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isMemberOf: sequence)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -375,9 +557,15 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
|
|||||||
let dog = dataStack.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> {
|
public func == <O: NSManagedObject, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<D>>,
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: objectID
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,9 +574,15 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
|||||||
let dog = dataStack.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> {
|
public func != <O: NSManagedObject, D: NSManagedObject>(
|
||||||
|
_ keyPath: KeyPath<O, Optional<D>>,
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
return !Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: objectID
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -397,9 +591,15 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
|||||||
let dog = dataStack.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 {
|
public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ keyPath: KeyPath<O, Optional<D>>
|
||||||
|
) -> Where<O> where S.Iterator.Element == NSManagedObjectID {
|
||||||
|
|
||||||
return Where<O>(keyPath._kvcKeyPathString!, isMemberOf: sequence)
|
return Where<O>(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -411,9 +611,15 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$nickname == "John"))
|
let person = dataStack.fetchOne(From<Person>().where(\.$nickname == "John"))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func == <O, V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> {
|
public func == <O, V>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(keyPath, isEqualTo: value)
|
return Where<O>(
|
||||||
|
keyPath,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -422,9 +628,15 @@ public func == <O, V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ valu
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$nickname != "John"))
|
let person = dataStack.fetchOne(From<Person>().where(\.$nickname != "John"))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func != <O, V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> {
|
public func != <O, V>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where<O>(keyPath, isEqualTo: value)
|
return !Where<O>(
|
||||||
|
keyPath,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -433,9 +645,15 @@ public func != <O, V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ valu
|
|||||||
let dog = dataStack.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, FieldContainer<O>.Stored<V>>) -> Where<O> where S.Iterator.Element == V {
|
public func ~= <O, V, S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>
|
||||||
|
) -> Where<O> where S.Iterator.Element == V {
|
||||||
|
|
||||||
return Where<O>(O.meta[keyPath: keyPath].keyPath, isMemberOf: sequence)
|
return Where<O>(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -447,9 +665,16 @@ public func ~= <O, V, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, FieldCon
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$age < 20))
|
let person = dataStack.fetchOne(From<Person>().where(\.$age < 20))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func < <O, V: Comparable>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> {
|
public func < <O, V: Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>("%K < %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType)
|
return Where<O>(
|
||||||
|
"%K < %@",
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -458,9 +683,16 @@ public func < <O, V: Comparable>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$age < 20))
|
let person = dataStack.fetchOne(From<Person>().where(\.$age < 20))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func < <O, V: FieldOptionalType>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> where V.Wrapped: Comparable {
|
public func < <O, V: FieldOptionalType>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> where V.Wrapped: Comparable {
|
||||||
|
|
||||||
return Where<O>("%K < %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType)
|
return Where<O>(
|
||||||
|
"%K < %@",
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -469,9 +701,16 @@ public func < <O, V: FieldOptionalType>(_ keyPath: KeyPath<O, FieldContainer<O>.
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$age > 20))
|
let person = dataStack.fetchOne(From<Person>().where(\.$age > 20))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func > <O, V: Comparable>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> {
|
public func > <O, V: Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>("%K > %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType)
|
return Where<O>(
|
||||||
|
"%K > %@",
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -480,9 +719,16 @@ public func > <O, V: Comparable>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$age > 20))
|
let person = dataStack.fetchOne(From<Person>().where(\.$age > 20))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func > <O, V: FieldOptionalType>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> where V.Wrapped: Comparable {
|
public func > <O, V: FieldOptionalType>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> where V.Wrapped: Comparable {
|
||||||
|
|
||||||
return Where<O>("%K > %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType)
|
return Where<O>(
|
||||||
|
"%K > %@",
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -491,9 +737,16 @@ public func > <O, V: FieldOptionalType>(_ keyPath: KeyPath<O, FieldContainer<O>.
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$age <= 20))
|
let person = dataStack.fetchOne(From<Person>().where(\.$age <= 20))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func <= <O, V: Comparable>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> {
|
public func <= <O, V: Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>("%K <= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType)
|
return Where<O>(
|
||||||
|
"%K <= %@",
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -502,9 +755,16 @@ public func <= <O, V: Comparable>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$age <= 20))
|
let person = dataStack.fetchOne(From<Person>().where(\.$age <= 20))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func <= <O, V: FieldOptionalType>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> where V.Wrapped: Comparable {
|
public func <= <O, V: FieldOptionalType>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> where V.Wrapped: Comparable {
|
||||||
|
|
||||||
return Where<O>("%K <= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType)
|
return Where<O>(
|
||||||
|
"%K <= %@",
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -513,9 +773,16 @@ public func <= <O, V: FieldOptionalType>(_ keyPath: KeyPath<O, FieldContainer<O>
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$age >= 20))
|
let person = dataStack.fetchOne(From<Person>().where(\.$age >= 20))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func >= <O, V: Comparable>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> {
|
public func >= <O, V: Comparable>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>("%K >= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType)
|
return Where<O>(
|
||||||
|
"%K >= %@",
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -524,9 +791,16 @@ public func >= <O, V: Comparable>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored
|
|||||||
let person = dataStack.fetchOne(From<Person>().where(\.$age >= 20))
|
let person = dataStack.fetchOne(From<Person>().where(\.$age >= 20))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func >= <O, V: FieldOptionalType>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> where V.Wrapped: Comparable {
|
public func >= <O, V: FieldOptionalType>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
_ value: V
|
||||||
|
) -> Where<O> where V.Wrapped: Comparable {
|
||||||
|
|
||||||
return Where<O>("%K >= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType)
|
return Where<O>(
|
||||||
|
"%K >= %@",
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -538,9 +812,15 @@ public func >= <O, V: FieldOptionalType>(_ keyPath: KeyPath<O, FieldContainer<O>
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where(\.$master == john))
|
let dog = dataStack.fetchOne(From<Dog>().where(\.$master == john))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func == <O, D: FieldRelationshipToOneType>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ object: D.DestinationObjectType?) -> Where<O> {
|
public func == <O, D: FieldRelationshipToOneType>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>,
|
||||||
|
_ object: D.DestinationObjectType?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object)
|
return Where<O>(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isEqualTo: object
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -549,9 +829,15 @@ public func == <O, D: FieldRelationshipToOneType>(_ keyPath: KeyPath<O, FieldCon
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func == <O, D: FieldRelationshipToOneType, R: ObjectRepresentation>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ object: R?) -> Where<O> where D.DestinationObjectType == R.ObjectType {
|
public func == <O, D: FieldRelationshipToOneType, R: ObjectRepresentation>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>,
|
||||||
|
_ object: R?
|
||||||
|
) -> Where<O> where D.DestinationObjectType == R.ObjectType {
|
||||||
|
|
||||||
return Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object?.objectID())
|
return Where<O>(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isEqualTo: object?.objectID()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -560,9 +846,15 @@ public func == <O, D: FieldRelationshipToOneType, R: ObjectRepresentation>(_ key
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where(\.$master != john))
|
let dog = dataStack.fetchOne(From<Dog>().where(\.$master != john))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func != <O, D: FieldRelationshipToOneType>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ object: D.DestinationObjectType?) -> Where<O> {
|
public func != <O, D: FieldRelationshipToOneType>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>,
|
||||||
|
_ object: D.DestinationObjectType?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return !Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object)
|
return !Where<O>(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isEqualTo: object
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -571,9 +863,15 @@ public func != <O, D: FieldRelationshipToOneType>(_ keyPath: KeyPath<O, FieldCon
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func != <O, D: FieldRelationshipToOneType, R: ObjectRepresentation>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ object: R?) -> Where<O> where D.DestinationObjectType == R.ObjectType {
|
public func != <O, D: FieldRelationshipToOneType, R: ObjectRepresentation>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>,
|
||||||
|
_ object: R?
|
||||||
|
) -> Where<O> where D.DestinationObjectType == R.ObjectType {
|
||||||
|
|
||||||
return !Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object?.objectID())
|
return !Where<O>(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isEqualTo: object?.objectID()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -582,9 +880,15 @@ public func != <O, D: FieldRelationshipToOneType, R: ObjectRepresentation>(_ key
|
|||||||
let dog = dataStack.fetchOne(From<Dog>().where([john, bob, joe] ~= \.$master))
|
let dog = dataStack.fetchOne(From<Dog>().where([john, bob, joe] ~= \.$master))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~= <O, D: FieldRelationshipToOneType, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>) -> Where<O> where S.Iterator.Element == D.DestinationObjectType {
|
public func ~= <O, D: FieldRelationshipToOneType, S: Sequence>(
|
||||||
|
_ sequence: S,
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>
|
||||||
|
) -> Where<O> where S.Iterator.Element == D.DestinationObjectType {
|
||||||
|
|
||||||
return Where<O>(O.meta[keyPath: keyPath].keyPath, isMemberOf: sequence)
|
return Where<O>(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isMemberOf: sequence
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,9 @@ extension ListPublisher.ReactiveNamespace {
|
|||||||
- parameter emitInitialValue: If `true`, the current value is immediately emitted to the first subscriber. If `false`, the event fires only starting the next `ListSnapshot` update.
|
- parameter emitInitialValue: If `true`, the current value is immediately emitted to the first subscriber. If `false`, the event fires only starting the next `ListSnapshot` update.
|
||||||
- returns: A `Publisher` that emits a `ListSnapshot` whenever changes occur in the `ListPublisher`.
|
- returns: A `Publisher` that emits a `ListSnapshot` whenever changes occur in the `ListPublisher`.
|
||||||
*/
|
*/
|
||||||
public func snapshot(emitInitialValue: Bool = true) -> ListPublisher.SnapshotPublisher {
|
public func snapshot(
|
||||||
|
emitInitialValue: Bool = true
|
||||||
|
) -> ListPublisher.SnapshotPublisher {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
listPublisher: self.base,
|
listPublisher: self.base,
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ extension ListPublisher {
|
|||||||
public typealias Output = ListSnapshot<O>
|
public typealias Output = ListSnapshot<O>
|
||||||
public typealias Failure = Never
|
public typealias Failure = Never
|
||||||
|
|
||||||
public func receive<S: Subscriber>(subscriber: S) where S.Input == Output, S.Failure == Failure {
|
public func receive<S: Subscriber>(
|
||||||
|
subscriber: S
|
||||||
|
) where S.Input == Output, S.Failure == Failure {
|
||||||
|
|
||||||
subscriber.receive(
|
subscriber.receive(
|
||||||
subscription: ListSnapshotSubscription(
|
subscription: ListSnapshotSubscription(
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ public final class ListPublisher<O: DynamicObject>: Hashable {
|
|||||||
public func refetch<B: FetchChainableBuilderType>(
|
public func refetch<B: FetchChainableBuilderType>(
|
||||||
_ clauseChain: B,
|
_ clauseChain: B,
|
||||||
sourceIdentifier: Any? = nil
|
sourceIdentifier: Any? = nil
|
||||||
) throws where B.ObjectType == O {
|
) throws(any Swift.Error) where B.ObjectType == O {
|
||||||
|
|
||||||
try self.refetch(
|
try self.refetch(
|
||||||
from: clauseChain.from,
|
from: clauseChain.from,
|
||||||
@@ -215,7 +215,7 @@ public final class ListPublisher<O: DynamicObject>: Hashable {
|
|||||||
public func refetch<B: SectionMonitorBuilderType>(
|
public func refetch<B: SectionMonitorBuilderType>(
|
||||||
_ clauseChain: B,
|
_ clauseChain: B,
|
||||||
sourceIdentifier: Any? = nil
|
sourceIdentifier: Any? = nil
|
||||||
) throws where B.ObjectType == O {
|
) throws(any Swift.Error) where B.ObjectType == O {
|
||||||
|
|
||||||
try self.refetch(
|
try self.refetch(
|
||||||
from: clauseChain.from,
|
from: clauseChain.from,
|
||||||
@@ -343,7 +343,7 @@ public final class ListPublisher<O: DynamicObject>: Hashable {
|
|||||||
sectionBy: SectionBy<O>?,
|
sectionBy: SectionBy<O>?,
|
||||||
applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest<NSManagedObject>) -> Void,
|
applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest<NSManagedObject>) -> Void,
|
||||||
sourceIdentifier: Any?
|
sourceIdentifier: Any?
|
||||||
) throws {
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
let (newFetchedResultsController, newFetchedResultsControllerDelegate) = Self.recreateFetchedResultsController(
|
let (newFetchedResultsController, newFetchedResultsControllerDelegate) = Self.recreateFetchedResultsController(
|
||||||
context: self.fetchedResultsController.managedObjectContext,
|
context: self.fetchedResultsController.managedObjectContext,
|
||||||
|
|||||||
@@ -32,7 +32,12 @@ import Foundation
|
|||||||
extension NSEntityDescription {
|
extension NSEntityDescription {
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func cs_resolveAttributeNames() -> [String: (attribute: NSAttributeDescription, versionHash: Data)] {
|
internal func cs_resolveAttributeNames() -> [
|
||||||
|
String: (
|
||||||
|
attribute: NSAttributeDescription,
|
||||||
|
versionHash: Data
|
||||||
|
)
|
||||||
|
] {
|
||||||
|
|
||||||
return self.attributesByName.reduce(
|
return self.attributesByName.reduce(
|
||||||
into: [:],
|
into: [:],
|
||||||
@@ -44,7 +49,12 @@ extension NSEntityDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func cs_resolveAttributeRenamingIdentities() -> [String: (attribute: NSAttributeDescription, versionHash: Data)] {
|
internal func cs_resolveAttributeRenamingIdentities() -> [
|
||||||
|
String: (
|
||||||
|
attribute: NSAttributeDescription,
|
||||||
|
versionHash: Data
|
||||||
|
)
|
||||||
|
] {
|
||||||
|
|
||||||
return self.attributesByName.reduce(
|
return self.attributesByName.reduce(
|
||||||
into: [:],
|
into: [:],
|
||||||
@@ -56,7 +66,12 @@ extension NSEntityDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func cs_resolveRelationshipNames() -> [String: (relationship: NSRelationshipDescription, versionHash: Data)] {
|
internal func cs_resolveRelationshipNames() -> [
|
||||||
|
String: (
|
||||||
|
relationship: NSRelationshipDescription,
|
||||||
|
versionHash: Data
|
||||||
|
)
|
||||||
|
] {
|
||||||
|
|
||||||
return self.relationshipsByName.reduce(
|
return self.relationshipsByName.reduce(
|
||||||
into: [:],
|
into: [:],
|
||||||
@@ -68,7 +83,12 @@ extension NSEntityDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func cs_resolveRelationshipRenamingIdentities() -> [String: (relationship: NSRelationshipDescription, versionHash: Data)] {
|
internal func cs_resolveRelationshipRenamingIdentities() -> [
|
||||||
|
String: (
|
||||||
|
relationship: NSRelationshipDescription,
|
||||||
|
versionHash: Data
|
||||||
|
)
|
||||||
|
] {
|
||||||
|
|
||||||
return self.relationshipsByName.reduce(
|
return self.relationshipsByName.reduce(
|
||||||
into: [:],
|
into: [:],
|
||||||
|
|||||||
@@ -41,7 +41,11 @@ extension DataStack {
|
|||||||
- returns: an `NSFetchedResultsController` that observes the `DataStack`
|
- returns: an `NSFetchedResultsController` that observes the `DataStack`
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func createFetchedResultsController<O: NSManagedObject>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<O> {
|
public func createFetchedResultsController<O: NSManagedObject>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
return Internals.createFRC(
|
return Internals.createFRC(
|
||||||
fromContext: self.mainContext,
|
fromContext: self.mainContext,
|
||||||
@@ -61,7 +65,11 @@ extension DataStack {
|
|||||||
- returns: an `NSFetchedResultsController` that observes the `DataStack`
|
- returns: an `NSFetchedResultsController` that observes the `DataStack`
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func createFetchedResultsController<O: NSManagedObject>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<O> {
|
public func createFetchedResultsController<O: NSManagedObject>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
return Internals.createFRC(
|
return Internals.createFRC(
|
||||||
fromContext: self.mainContext,
|
fromContext: self.mainContext,
|
||||||
@@ -80,7 +88,10 @@ extension DataStack {
|
|||||||
- returns: an `NSFetchedResultsController` that observes the `DataStack`
|
- returns: an `NSFetchedResultsController` that observes the `DataStack`
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func createFetchedResultsController<O: NSManagedObject>(_ from: From<O>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<O> {
|
public func createFetchedResultsController<O: NSManagedObject>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
return Internals.createFRC(
|
return Internals.createFRC(
|
||||||
fromContext: self.mainContext,
|
fromContext: self.mainContext,
|
||||||
@@ -99,7 +110,11 @@ extension DataStack {
|
|||||||
- returns: an `NSFetchedResultsController` that observes the `DataStack`
|
- returns: an `NSFetchedResultsController` that observes the `DataStack`
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func createFetchedResultsController<O: NSManagedObject>(forDataStack dataStack: DataStack, _ from: From<O>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<O> {
|
public func createFetchedResultsController<O: NSManagedObject>(
|
||||||
|
forDataStack dataStack: DataStack,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
return Internals.createFRC(
|
return Internals.createFRC(
|
||||||
fromContext: self.mainContext,
|
fromContext: self.mainContext,
|
||||||
@@ -125,7 +140,11 @@ extension UnsafeDataTransaction {
|
|||||||
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
|
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func createFetchedResultsController<O: NSManagedObject>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<O> {
|
public func createFetchedResultsController<O: NSManagedObject>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
return Internals.createFRC(
|
return Internals.createFRC(
|
||||||
fromContext: self.context,
|
fromContext: self.context,
|
||||||
@@ -145,7 +164,11 @@ extension UnsafeDataTransaction {
|
|||||||
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
|
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func createFetchedResultsController<O: NSManagedObject>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<O> {
|
public func createFetchedResultsController<O: NSManagedObject>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
return Internals.createFRC(
|
return Internals.createFRC(
|
||||||
fromContext: self.context,
|
fromContext: self.context,
|
||||||
@@ -164,7 +187,10 @@ extension UnsafeDataTransaction {
|
|||||||
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
|
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func createFetchedResultsController<O: NSManagedObject>(_ from: From<O>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<O> {
|
public func createFetchedResultsController<O: NSManagedObject>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
return Internals.createFRC(
|
return Internals.createFRC(
|
||||||
fromContext: self.context,
|
fromContext: self.context,
|
||||||
@@ -183,7 +209,10 @@ extension UnsafeDataTransaction {
|
|||||||
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
|
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
|
||||||
*/
|
*/
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func createFetchedResultsController<O: NSManagedObject>(_ from: From<O>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<O> {
|
public func createFetchedResultsController<O: NSManagedObject>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
return Internals.createFRC(
|
return Internals.createFRC(
|
||||||
fromContext: self.context,
|
fromContext: self.context,
|
||||||
@@ -202,7 +231,12 @@ extension Internals {
|
|||||||
|
|
||||||
// MARK: FilePrivate
|
// MARK: FilePrivate
|
||||||
|
|
||||||
fileprivate static func createFRC<O: NSManagedObject>(fromContext context: NSManagedObjectContext, from: From<O>, sectionBy: SectionBy<O>? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController<O> {
|
fileprivate static func createFRC<O: NSManagedObject>(
|
||||||
|
fromContext context: NSManagedObjectContext,
|
||||||
|
from: From<O>,
|
||||||
|
sectionBy: SectionBy<O>? = nil,
|
||||||
|
fetchClauses: [FetchClause]
|
||||||
|
) -> NSFetchedResultsController<O> {
|
||||||
|
|
||||||
let controller = Internals.CoreStoreFetchedResultsController(
|
let controller = Internals.CoreStoreFetchedResultsController(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
@@ -84,7 +84,9 @@ extension NSManagedObject {
|
|||||||
- returns: the primitive value for the KVC key
|
- returns: the primitive value for the KVC key
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func getValue(forKvcKey kvcKey: KeyPathString) -> Any? {
|
public func getValue(
|
||||||
|
forKvcKey kvcKey: KeyPathString
|
||||||
|
) -> Any? {
|
||||||
|
|
||||||
self.willAccessValue(forKey: kvcKey)
|
self.willAccessValue(forKey: kvcKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -102,7 +104,10 @@ extension NSManagedObject {
|
|||||||
- returns: the primitive value transformed by the `didGetValue` closure
|
- returns: the primitive value transformed by the `didGetValue` closure
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func getValue<T>(forKvcKey kvcKey: KeyPathString, didGetValue: (Any?) throws -> T) rethrows -> T {
|
public func getValue<T>(
|
||||||
|
forKvcKey kvcKey: KeyPathString,
|
||||||
|
didGetValue: (Any?) throws(any Swift.Error) -> T
|
||||||
|
) rethrows -> T {
|
||||||
|
|
||||||
self.willAccessValue(forKey: kvcKey)
|
self.willAccessValue(forKey: kvcKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -121,7 +126,11 @@ extension NSManagedObject {
|
|||||||
- returns: the primitive value transformed by the `didGetValue` closure
|
- returns: the primitive value transformed by the `didGetValue` closure
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func getValue<T>(forKvcKey kvcKey: KeyPathString, willGetValue: () throws -> Void, didGetValue: (Any?) throws -> T) rethrows -> T {
|
public func getValue<T>(
|
||||||
|
forKvcKey kvcKey: KeyPathString,
|
||||||
|
willGetValue: () throws(any Swift.Error) -> Void,
|
||||||
|
didGetValue: (Any?) throws(any Swift.Error) -> T
|
||||||
|
) rethrows -> T {
|
||||||
|
|
||||||
self.willAccessValue(forKey: kvcKey)
|
self.willAccessValue(forKey: kvcKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -139,7 +148,10 @@ extension NSManagedObject {
|
|||||||
- parameter KVCKey: the KVC key
|
- parameter KVCKey: the KVC key
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPathString) {
|
public func setValue(
|
||||||
|
_ value: Any?,
|
||||||
|
forKvcKey KVCKey: KeyPathString
|
||||||
|
) {
|
||||||
|
|
||||||
self.willChangeValue(forKey: KVCKey)
|
self.willChangeValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -157,7 +169,11 @@ extension NSManagedObject {
|
|||||||
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
|
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPathString, didSetValue: () -> Void) {
|
public func setValue(
|
||||||
|
_ value: Any?,
|
||||||
|
forKvcKey KVCKey: KeyPathString,
|
||||||
|
didSetValue: () -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.willChangeValue(forKey: KVCKey)
|
self.willChangeValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
@@ -177,7 +193,12 @@ extension NSManagedObject {
|
|||||||
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
|
- parameter didSetValue: called after executing `setPrimitiveValue(forKey:)`.
|
||||||
*/
|
*/
|
||||||
@nonobjc @inline(__always)
|
@nonobjc @inline(__always)
|
||||||
public func setValue<T>(_ value: T, forKvcKey KVCKey: KeyPathString, willSetValue: (T) throws -> Any?, didSetValue: (Any?) -> Void = { _ in }) rethrows {
|
public func setValue<T>(
|
||||||
|
_ value: T,
|
||||||
|
forKvcKey KVCKey: KeyPathString,
|
||||||
|
willSetValue: (T) throws(any Swift.Error) -> Any?,
|
||||||
|
didSetValue: (Any?) -> Void = { _ in }
|
||||||
|
) rethrows {
|
||||||
|
|
||||||
self.willChangeValue(forKey: KVCKey)
|
self.willChangeValue(forKey: KVCKey)
|
||||||
defer {
|
defer {
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
// MARK: FetchableSource
|
// MARK: FetchableSource
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchExisting<O: DynamicObject>(_ object: O) -> O? {
|
public func fetchExisting<O: DynamicObject>(
|
||||||
|
_ object: O
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
let rawObject = object.cs_toRaw()
|
let rawObject = object.cs_toRaw()
|
||||||
if rawObject.objectID.isTemporaryID {
|
if rawObject.objectID.isTemporaryID {
|
||||||
@@ -75,7 +77,9 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchExisting<O: DynamicObject>(_ objectID: NSManagedObjectID) -> O? {
|
public func fetchExisting<O: DynamicObject>(
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
@@ -89,25 +93,35 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchExisting<O: DynamicObject, S: Sequence>(_ objects: S) -> [O] where S.Iterator.Element == O {
|
public func fetchExisting<O: DynamicObject, S: Sequence>(
|
||||||
|
_ objects: S
|
||||||
|
) -> [O] where S.Iterator.Element == O {
|
||||||
|
|
||||||
return objects.compactMap({ self.fetchExisting($0.cs_id()) })
|
return objects.compactMap({ self.fetchExisting($0.cs_id()) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchExisting<O: DynamicObject, S: Sequence>(_ objectIDs: S) -> [O] where S.Iterator.Element == NSManagedObjectID {
|
public func fetchExisting<O: DynamicObject, S: Sequence>(
|
||||||
|
_ objectIDs: S
|
||||||
|
) -> [O] where S.Iterator.Element == NSManagedObjectID {
|
||||||
|
|
||||||
return objectIDs.compactMap({ self.fetchExisting($0) })
|
return objectIDs.compactMap({ self.fetchExisting($0) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> O? {
|
public func fetchOne<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> O? {
|
||||||
|
|
||||||
return try self.fetchOne(from, fetchClauses)
|
return try self.fetchOne(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchOne<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> O? {
|
public func fetchOne<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> O? {
|
||||||
|
|
||||||
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObject>()
|
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObject>()
|
||||||
try from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -120,19 +134,30 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType? {
|
public func fetchOne<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> B.ObjectType? {
|
||||||
|
|
||||||
return try self.fetchOne(clauseChain.from, clauseChain.fetchClauses)
|
return try self.fetchOne(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.fetchClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [O] {
|
public func fetchAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> [O] {
|
||||||
|
|
||||||
return try self.fetchAll(from, fetchClauses)
|
return try self.fetchAll(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchAll<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [O] {
|
public func fetchAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> [O] {
|
||||||
|
|
||||||
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObject>()
|
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObject>()
|
||||||
try from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -146,19 +171,30 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType] {
|
public func fetchAll<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [B.ObjectType] {
|
||||||
|
|
||||||
return try self.fetchAll(clauseChain.from, clauseChain.fetchClauses)
|
return try self.fetchAll(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.fetchClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> Int {
|
public func fetchCount<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
return try self.fetchCount(from, fetchClauses)
|
return try self.fetchCount(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchCount<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> Int {
|
public func fetchCount<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
let fetchRequest = Internals.CoreStoreFetchRequest<NSNumber>()
|
let fetchRequest = Internals.CoreStoreFetchRequest<NSNumber>()
|
||||||
try from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -170,19 +206,30 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
public func fetchCount<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
return try self.fetchCount(clauseChain.from, clauseChain.fetchClauses)
|
return try self.fetchCount(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.fetchClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? {
|
public func fetchObjectID<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
return try self.fetchObjectID(from, fetchClauses)
|
return try self.fetchObjectID(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectID<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? {
|
public func fetchObjectID<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObjectID>()
|
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObjectID>()
|
||||||
try from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -195,19 +242,30 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> NSManagedObjectID? {
|
public func fetchObjectID<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
return try self.fetchObjectID(clauseChain.from, clauseChain.fetchClauses)
|
return try self.fetchObjectID(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.fetchClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
return try self.fetchObjectIDs(from, fetchClauses)
|
return try self.fetchObjectIDs(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectIDs<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObjectID>()
|
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObjectID>()
|
||||||
try from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -220,13 +278,20 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [NSManagedObjectID] {
|
public func fetchObjectIDs<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
return try self.fetchObjectIDs(clauseChain.from, clauseChain.fetchClauses)
|
return try self.fetchObjectIDs(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.fetchClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchObjectIDs(_ fetchRequest: Internals.CoreStoreFetchRequest<NSManagedObjectID>) throws -> [NSManagedObjectID] {
|
internal func fetchObjectIDs(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<NSManagedObjectID>
|
||||||
|
) throws(CoreStoreError) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
var fetchResults: [NSManagedObjectID]?
|
var fetchResults: [NSManagedObjectID]?
|
||||||
var fetchError: Error?
|
var fetchError: Error?
|
||||||
@@ -257,13 +322,21 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
// MARK: QueryableSource
|
// MARK: QueryableSource
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: QueryClause...) throws -> U? {
|
public func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, U>,
|
||||||
|
_ queryClauses: QueryClause...
|
||||||
|
) throws(CoreStoreError) -> U? {
|
||||||
|
|
||||||
return try self.queryValue(from, selectClause, queryClauses)
|
return try self.queryValue(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: [QueryClause]) throws -> U? {
|
public func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, U>,
|
||||||
|
_ queryClauses: [QueryClause]
|
||||||
|
) throws(CoreStoreError) -> U? {
|
||||||
|
|
||||||
let fetchRequest = Internals.CoreStoreFetchRequest<NSDictionary>()
|
let fetchRequest = Internals.CoreStoreFetchRequest<NSDictionary>()
|
||||||
try from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -277,19 +350,33 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryValue<B>(_ clauseChain: B) throws -> B.ResultType? where B: QueryChainableBuilderType, B.ResultType: QueryableAttributeType {
|
public func queryValue<B>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> B.ResultType? where B: QueryChainableBuilderType, B.ResultType: QueryableAttributeType {
|
||||||
|
|
||||||
return try self.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
return try self.queryValue(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.select,
|
||||||
|
clauseChain.queryClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: QueryClause...) throws -> [[String: Any]] {
|
public func queryAttributes<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, NSDictionary>,
|
||||||
|
_ queryClauses: QueryClause...
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] {
|
||||||
|
|
||||||
return try self.queryAttributes(from, selectClause, queryClauses)
|
return try self.queryAttributes(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: [QueryClause]) throws -> [[String: Any]] {
|
public func queryAttributes<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, NSDictionary>,
|
||||||
|
_ queryClauses: [QueryClause]
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] {
|
||||||
|
|
||||||
let fetchRequest = Internals.CoreStoreFetchRequest<NSDictionary>()
|
let fetchRequest = Internals.CoreStoreFetchRequest<NSDictionary>()
|
||||||
try from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -302,9 +389,15 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
return try self.queryAttributes(fetchRequest)
|
return try self.queryAttributes(fetchRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func queryAttributes<B>(_ clauseChain: B) throws -> [[String : Any]] where B : QueryChainableBuilderType, B.ResultType == NSDictionary {
|
public func queryAttributes<B>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [[String : Any]] where B : QueryChainableBuilderType, B.ResultType == NSDictionary {
|
||||||
|
|
||||||
return try self.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
return try self.queryAttributes(
|
||||||
|
clauseChain.from,
|
||||||
|
clauseChain.select,
|
||||||
|
clauseChain.queryClauses
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -320,7 +413,10 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
// MARK: Deleting
|
// MARK: Deleting
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func deleteAll<O>(_ from: From<O>, _ deleteClauses: [FetchClause]) throws -> Int {
|
internal func deleteAll<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ deleteClauses: [FetchClause]
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObject>()
|
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObject>()
|
||||||
try from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -343,10 +439,12 @@ extension NSManagedObjectContext {
|
|||||||
// MARK: Fetching
|
// MARK: Fetching
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchOne<O: NSManagedObject>(_ fetchRequest: Internals.CoreStoreFetchRequest<O>) throws -> O? {
|
internal func fetchOne<O: NSManagedObject>(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<O>
|
||||||
|
) throws(CoreStoreError) -> O? {
|
||||||
|
|
||||||
var fetchResults: [O]?
|
var fetchResults: [O]?
|
||||||
var fetchError: Error?
|
var fetchError: (any Swift.Error)?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -371,10 +469,12 @@ extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchAll<O: NSManagedObject>(_ fetchRequest: Internals.CoreStoreFetchRequest<O>) throws -> [O] {
|
internal func fetchAll<O: NSManagedObject>(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<O>
|
||||||
|
) throws(CoreStoreError) -> [O] {
|
||||||
|
|
||||||
var fetchResults: [O]?
|
var fetchResults: [O]?
|
||||||
var fetchError: Error?
|
var fetchError: (any Swift.Error)?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -399,10 +499,12 @@ extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchCount(_ fetchRequest: Internals.CoreStoreFetchRequest<NSNumber>) throws -> Int {
|
internal func fetchCount(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<NSNumber>
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
var count = 0
|
var count = 0
|
||||||
var countError: Error?
|
var countError: (any Swift.Error)?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -427,10 +529,12 @@ extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchObjectID(_ fetchRequest: Internals.CoreStoreFetchRequest<NSManagedObjectID>) throws -> NSManagedObjectID? {
|
internal func fetchObjectID(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<NSManagedObjectID>
|
||||||
|
) throws(CoreStoreError) -> NSManagedObjectID? {
|
||||||
|
|
||||||
var fetchResults: [NSManagedObjectID]?
|
var fetchResults: [NSManagedObjectID]?
|
||||||
var fetchError: Error?
|
var fetchError: (any Swift.Error)?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -458,10 +562,13 @@ extension NSManagedObjectContext {
|
|||||||
// MARK: Querying
|
// MARK: Querying
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func queryValue<O, U: QueryableAttributeType>(_ selectTerms: [SelectTerm<O>], fetchRequest: Internals.CoreStoreFetchRequest<NSDictionary>) throws -> U? {
|
internal func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ selectTerms: [SelectTerm<O>],
|
||||||
|
fetchRequest: Internals.CoreStoreFetchRequest<NSDictionary>
|
||||||
|
) throws(CoreStoreError) -> U? {
|
||||||
|
|
||||||
var fetchResults: [Any]?
|
var fetchResults: [Any]?
|
||||||
var fetchError: Error?
|
var fetchError: (any Swift.Error)?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -491,10 +598,13 @@ extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func queryValue<O>(_ selectTerms: [SelectTerm<O>], fetchRequest: Internals.CoreStoreFetchRequest<NSDictionary>) throws -> Any? {
|
internal func queryValue<O>(
|
||||||
|
_ selectTerms: [SelectTerm<O>],
|
||||||
|
fetchRequest: Internals.CoreStoreFetchRequest<NSDictionary>
|
||||||
|
) throws(CoreStoreError) -> Any? {
|
||||||
|
|
||||||
var fetchResults: [Any]?
|
var fetchResults: [Any]?
|
||||||
var fetchError: Error?
|
var fetchError: (any Swift.Error)?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -524,10 +634,12 @@ extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func queryAttributes(_ fetchRequest: Internals.CoreStoreFetchRequest<NSDictionary>) throws -> [[String: Any]] {
|
internal func queryAttributes(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<NSDictionary>
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] {
|
||||||
|
|
||||||
var fetchResults: [Any]?
|
var fetchResults: [Any]?
|
||||||
var fetchError: Error?
|
var fetchError: (any Swift.Error)?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -555,13 +667,15 @@ extension NSManagedObjectContext {
|
|||||||
// MARK: Deleting
|
// MARK: Deleting
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func deleteAll<O: NSManagedObject>(_ fetchRequest: Internals.CoreStoreFetchRequest<O>) throws -> Int {
|
internal func deleteAll<O: NSManagedObject>(
|
||||||
|
_ fetchRequest: Internals.CoreStoreFetchRequest<O>
|
||||||
|
) throws(CoreStoreError) -> Int {
|
||||||
|
|
||||||
var numberOfDeletedObjects: Int?
|
var numberOfDeletedObjects: Int?
|
||||||
var fetchError: Error?
|
var fetchError: (any Swift.Error)?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
autoreleasepool {
|
Internals.autoreleasepool {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
|
|||||||
@@ -32,13 +32,17 @@ import CoreData
|
|||||||
extension NSPersistentStoreCoordinator {
|
extension NSPersistentStoreCoordinator {
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func performAsynchronously(_ closure: @escaping () -> Void) {
|
internal func performAsynchronously(
|
||||||
|
_ closure: @escaping () -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.perform(closure)
|
self.perform(closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func performSynchronously<T>(_ closure: @escaping () -> T) -> T {
|
internal func performSynchronously<T>(
|
||||||
|
_ closure: @escaping () -> T
|
||||||
|
) -> T {
|
||||||
|
|
||||||
var result: T?
|
var result: T?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
@@ -49,9 +53,11 @@ extension NSPersistentStoreCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func performSynchronously<T>(_ closure: @escaping () throws -> T) throws -> T {
|
internal func performSynchronously<T>(
|
||||||
|
_ closure: @escaping () throws(any Swift.Error) -> T
|
||||||
|
) throws(CoreStoreError) -> T {
|
||||||
|
|
||||||
var closureError: Error?
|
var closureError: (any Swift.Error)?
|
||||||
var result: T?
|
var result: T?
|
||||||
self.performAndWait {
|
self.performAndWait {
|
||||||
|
|
||||||
@@ -66,18 +72,21 @@ extension NSPersistentStoreCoordinator {
|
|||||||
}
|
}
|
||||||
if let closureError = closureError {
|
if let closureError = closureError {
|
||||||
|
|
||||||
throw closureError
|
throw CoreStoreError(closureError)
|
||||||
}
|
}
|
||||||
return result!
|
return result!
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func addPersistentStoreSynchronously(_ storeType: String, configuration: ModelConfiguration, URL storeURL: URL?, options: [AnyHashable: Any]?) throws -> NSPersistentStore {
|
internal func addPersistentStoreSynchronously(
|
||||||
|
_ storeType: String,
|
||||||
|
configuration: ModelConfiguration,
|
||||||
|
URL storeURL: URL?,
|
||||||
|
options: [AnyHashable: Any]?
|
||||||
|
) throws(CoreStoreError) -> NSPersistentStore {
|
||||||
|
|
||||||
return try self.performSynchronously {
|
return try self.performSynchronously {
|
||||||
|
|
||||||
do {
|
|
||||||
|
|
||||||
return try self.addPersistentStore(
|
return try self.addPersistentStore(
|
||||||
ofType: storeType,
|
ofType: storeType,
|
||||||
configurationName: configuration,
|
configurationName: configuration,
|
||||||
@@ -85,10 +94,5 @@ extension NSPersistentStoreCoordinator {
|
|||||||
options: options
|
options: options
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
catch {
|
|
||||||
|
|
||||||
throw CoreStoreError(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ public struct ObjectProxy<O: CoreStoreObject> {
|
|||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
public subscript<OBase, V>(dynamicMember member: KeyPath<O, FieldContainer<OBase>.Stored<V>>) -> FieldProxy<V> {
|
public subscript<OBase, V>(
|
||||||
|
dynamicMember member: KeyPath<O, FieldContainer<OBase>.Stored<V>>
|
||||||
|
) -> FieldProxy<V> {
|
||||||
|
|
||||||
return .init(rawObject: self.rawObject, keyPath: member)
|
return .init(rawObject: self.rawObject, keyPath: member)
|
||||||
}
|
}
|
||||||
@@ -46,7 +48,9 @@ public struct ObjectProxy<O: CoreStoreObject> {
|
|||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
public subscript<OBase, V>(dynamicMember member: KeyPath<O, FieldContainer<OBase>.Virtual<V>>) -> FieldProxy<V> {
|
public subscript<OBase, V>(
|
||||||
|
dynamicMember member: KeyPath<O, FieldContainer<OBase>.Virtual<V>>
|
||||||
|
) -> FieldProxy<V> {
|
||||||
|
|
||||||
return .init(rawObject: self.rawObject, keyPath: member)
|
return .init(rawObject: self.rawObject, keyPath: member)
|
||||||
}
|
}
|
||||||
@@ -54,7 +58,9 @@ public struct ObjectProxy<O: CoreStoreObject> {
|
|||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
public subscript<OBase, V>(dynamicMember member: KeyPath<O, FieldContainer<OBase>.Coded<V>>) -> FieldProxy<V> {
|
public subscript<OBase, V>(
|
||||||
|
dynamicMember member: KeyPath<O, FieldContainer<OBase>.Coded<V>>
|
||||||
|
) -> FieldProxy<V> {
|
||||||
|
|
||||||
return .init(rawObject: self.rawObject, keyPath: member)
|
return .init(rawObject: self.rawObject, keyPath: member)
|
||||||
}
|
}
|
||||||
@@ -111,22 +117,34 @@ public struct ObjectProxy<O: CoreStoreObject> {
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal init<OBase>(rawObject: CoreStoreManagedObject, keyPath: KeyPath<O, FieldContainer<OBase>.Stored<V>>) {
|
internal init<OBase>(
|
||||||
|
rawObject: CoreStoreManagedObject,
|
||||||
|
keyPath: KeyPath<O, FieldContainer<OBase>.Stored<V>>
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(rawObject: rawObject, field: O.meta[keyPath: keyPath])
|
self.init(rawObject: rawObject, field: O.meta[keyPath: keyPath])
|
||||||
}
|
}
|
||||||
|
|
||||||
internal init<OBase>(rawObject: CoreStoreManagedObject, keyPath: KeyPath<O, FieldContainer<OBase>.Virtual<V>>) {
|
internal init<OBase>(
|
||||||
|
rawObject: CoreStoreManagedObject,
|
||||||
|
keyPath: KeyPath<O, FieldContainer<OBase>.Virtual<V>>
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(rawObject: rawObject, field: O.meta[keyPath: keyPath])
|
self.init(rawObject: rawObject, field: O.meta[keyPath: keyPath])
|
||||||
}
|
}
|
||||||
|
|
||||||
internal init<OBase>(rawObject: CoreStoreManagedObject, keyPath: KeyPath<O, FieldContainer<OBase>.Coded<V>>) {
|
internal init<OBase>(
|
||||||
|
rawObject: CoreStoreManagedObject,
|
||||||
|
keyPath: KeyPath<O, FieldContainer<OBase>.Coded<V>>
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(rawObject: rawObject, field: O.meta[keyPath: keyPath])
|
self.init(rawObject: rawObject, field: O.meta[keyPath: keyPath])
|
||||||
}
|
}
|
||||||
|
|
||||||
internal init<OBase>(rawObject: CoreStoreManagedObject, field: FieldContainer<OBase>.Stored<V>) {
|
internal init<OBase>(
|
||||||
|
rawObject: CoreStoreManagedObject,
|
||||||
|
field: FieldContainer<OBase>.Stored<V>
|
||||||
|
) {
|
||||||
|
|
||||||
let keyPathString = field.keyPath
|
let keyPathString = field.keyPath
|
||||||
self.getValue = {
|
self.getValue = {
|
||||||
@@ -157,7 +175,10 @@ public struct ObjectProxy<O: CoreStoreObject> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal init<OBase>(rawObject: CoreStoreManagedObject, field: FieldContainer<OBase>.Virtual<V>) {
|
internal init<OBase>(
|
||||||
|
rawObject: CoreStoreManagedObject,
|
||||||
|
field: FieldContainer<OBase>.Virtual<V>
|
||||||
|
) {
|
||||||
|
|
||||||
let keyPathString = field.keyPath
|
let keyPathString = field.keyPath
|
||||||
self.getValue = {
|
self.getValue = {
|
||||||
@@ -190,7 +211,10 @@ public struct ObjectProxy<O: CoreStoreObject> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal init<OBase>(rawObject: CoreStoreManagedObject, field: FieldContainer<OBase>.Coded<V>) {
|
internal init<OBase>(
|
||||||
|
rawObject: CoreStoreManagedObject,
|
||||||
|
field: FieldContainer<OBase>.Coded<V>
|
||||||
|
) {
|
||||||
|
|
||||||
let keyPathString = field.keyPath
|
let keyPathString = field.keyPath
|
||||||
self.getValue = {
|
self.getValue = {
|
||||||
|
|||||||
@@ -94,7 +94,9 @@ extension ObjectPublisher.ReactiveNamespace {
|
|||||||
- parameter emitInitialValue: If `true`, the current value is immediately emitted to the first subscriber. If `false`, the event fires only starting the next `ObjectSnapshot` update.
|
- parameter emitInitialValue: If `true`, the current value is immediately emitted to the first subscriber. If `false`, the event fires only starting the next `ObjectSnapshot` update.
|
||||||
- returns: A `Publisher` that emits an `ObjectSnapshot?` whenever changes occur in the `ObjectPublisher`. The event emits `nil` if the object has been deletd.
|
- returns: A `Publisher` that emits an `ObjectSnapshot?` whenever changes occur in the `ObjectPublisher`. The event emits `nil` if the object has been deletd.
|
||||||
*/
|
*/
|
||||||
public func snapshot(emitInitialValue: Bool = true) -> ObjectPublisher.SnapshotPublisher {
|
public func snapshot(
|
||||||
|
emitInitialValue: Bool = true
|
||||||
|
) -> ObjectPublisher.SnapshotPublisher {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
objectPublisher: self.base,
|
objectPublisher: self.base,
|
||||||
@@ -111,7 +113,9 @@ extension ObjectPublisher.ReactiveNamespace where O: NSManagedObject {
|
|||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
public subscript<V: AllowedObjectiveCKeyPathValue>(dynamicMember member: KeyPath<O, V>) -> some Publisher {
|
public subscript<V: AllowedObjectiveCKeyPathValue>(
|
||||||
|
dynamicMember member: KeyPath<O, V>
|
||||||
|
) -> some Publisher {
|
||||||
|
|
||||||
return self
|
return self
|
||||||
.snapshot(emitInitialValue: true)
|
.snapshot(emitInitialValue: true)
|
||||||
@@ -127,7 +131,9 @@ extension ObjectPublisher.ReactiveNamespace where O: CoreStoreObject {
|
|||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
public subscript<OBase, V>(dynamicMember member: KeyPath<O, FieldContainer<OBase>.Stored<V>>) -> some Publisher {
|
public subscript<OBase, V>(
|
||||||
|
dynamicMember member: KeyPath<O, FieldContainer<OBase>.Stored<V>>
|
||||||
|
) -> some Publisher {
|
||||||
|
|
||||||
return self
|
return self
|
||||||
.snapshot(emitInitialValue: true)
|
.snapshot(emitInitialValue: true)
|
||||||
@@ -137,7 +143,9 @@ extension ObjectPublisher.ReactiveNamespace where O: CoreStoreObject {
|
|||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
public subscript<OBase, V>(dynamicMember member: KeyPath<O, FieldContainer<OBase>.Virtual<V>>) -> some Publisher {
|
public subscript<OBase, V>(
|
||||||
|
dynamicMember member: KeyPath<O, FieldContainer<OBase>.Virtual<V>>
|
||||||
|
) -> some Publisher {
|
||||||
|
|
||||||
return self
|
return self
|
||||||
.snapshot(emitInitialValue: true)
|
.snapshot(emitInitialValue: true)
|
||||||
@@ -147,7 +155,9 @@ extension ObjectPublisher.ReactiveNamespace where O: CoreStoreObject {
|
|||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
public subscript<OBase, V>(dynamicMember member: KeyPath<O, FieldContainer<OBase>.Coded<V>>) -> some Publisher {
|
public subscript<OBase, V>(
|
||||||
|
dynamicMember member: KeyPath<O, FieldContainer<OBase>.Coded<V>>
|
||||||
|
) -> some Publisher {
|
||||||
|
|
||||||
return self
|
return self
|
||||||
.snapshot(emitInitialValue: true)
|
.snapshot(emitInitialValue: true)
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ extension ObjectPublisher {
|
|||||||
public typealias Output = ObjectSnapshot<O>?
|
public typealias Output = ObjectSnapshot<O>?
|
||||||
public typealias Failure = Never
|
public typealias Failure = Never
|
||||||
|
|
||||||
public func receive<S: Subscriber>(subscriber: S) where S.Input == Output, S.Failure == Failure {
|
public func receive<S: Subscriber>(
|
||||||
|
subscriber: S
|
||||||
|
) where S.Input == Output, S.Failure == Failure {
|
||||||
|
|
||||||
subscriber.receive(
|
subscriber.receive(
|
||||||
subscription: ObjectSnapshotSubscription(
|
subscription: ObjectSnapshotSubscription(
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ public protocol QueryableSource: AnyObject {
|
|||||||
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: QueryClause...) throws -> U?
|
func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, U>,
|
||||||
|
_ queryClauses: QueryClause...
|
||||||
|
) throws(CoreStoreError) -> U?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||||
@@ -58,7 +62,11 @@ public protocol QueryableSource: AnyObject {
|
|||||||
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func queryValue<O, U: QueryableAttributeType>(_ from: From<O>, _ selectClause: Select<O, U>, _ queryClauses: [QueryClause]) throws -> U?
|
func queryValue<O, U: QueryableAttributeType>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, U>,
|
||||||
|
_ queryClauses: [QueryClause]
|
||||||
|
) throws(CoreStoreError) -> U?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Queries a property value or aggregate as specified by the `QueryChainableBuilderType` built from a chain of clauses.
|
Queries a property value or aggregate as specified by the `QueryChainableBuilderType` built from a chain of clauses.
|
||||||
@@ -75,7 +83,9 @@ public protocol QueryableSource: AnyObject {
|
|||||||
- returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found.
|
- returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType
|
func queryValue<B: QueryChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> B.ResultType? where B.ResultType: QueryableAttributeType
|
||||||
|
|
||||||
/**
|
/**
|
||||||
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.
|
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.
|
||||||
@@ -88,7 +98,11 @@ public protocol QueryableSource: AnyObject {
|
|||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: QueryClause...) throws -> [[String: Any]]
|
func queryAttributes<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, NSDictionary>,
|
||||||
|
_ queryClauses: QueryClause...
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
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.
|
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.
|
||||||
@@ -101,7 +115,11 @@ public protocol QueryableSource: AnyObject {
|
|||||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func queryAttributes<O>(_ from: From<O>, _ selectClause: Select<O, NSDictionary>, _ queryClauses: [QueryClause]) throws -> [[String: Any]]
|
func queryAttributes<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ selectClause: Select<O, NSDictionary>,
|
||||||
|
_ queryClauses: [QueryClause]
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Queries a dictionary of attribute values or as specified by the `QueryChainableBuilderType` built from a chain of clauses.
|
Queries a dictionary of attribute values or as specified by the `QueryChainableBuilderType` built from a chain of clauses.
|
||||||
@@ -127,7 +145,9 @@ public protocol QueryableSource: AnyObject {
|
|||||||
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
|
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
|
||||||
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
- throws: `CoreStoreError.persistentStoreNotFound` if the specified entity could not be found in any store's schema.
|
||||||
*/
|
*/
|
||||||
func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary
|
func queryAttributes<B: QueryChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) throws(CoreStoreError) -> [[String: Any]] where B.ResultType == NSDictionary
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The internal `NSManagedObjectContext` managed by this `QueryableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
The internal `NSManagedObjectContext` managed by this `QueryableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
||||||
|
|||||||
@@ -43,7 +43,12 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
- parameter migrationMappingProviders: an array of `SchemaMappingProviders` that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (as `InferredSchemaMappingProvider`) and may be omitted from the array.
|
- parameter migrationMappingProviders: an array of `SchemaMappingProviders` that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (as `InferredSchemaMappingProvider`) and may be omitted from the array.
|
||||||
- parameter localStorageOptions: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, tells the `DataStack` how to setup the persistent store. Defaults to `.none`.
|
- parameter localStorageOptions: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, tells the `DataStack` how to setup the persistent store. Defaults to `.none`.
|
||||||
*/
|
*/
|
||||||
public init(fileURL: URL, configuration: ModelConfiguration = nil, migrationMappingProviders: [SchemaMappingProvider] = [], localStorageOptions: LocalStorageOptions = nil) {
|
public init(
|
||||||
|
fileURL: URL,
|
||||||
|
configuration: ModelConfiguration = nil,
|
||||||
|
migrationMappingProviders: [SchemaMappingProvider] = [],
|
||||||
|
localStorageOptions: LocalStorageOptions = nil
|
||||||
|
) {
|
||||||
|
|
||||||
self.fileURL = fileURL
|
self.fileURL = fileURL
|
||||||
self.configuration = configuration
|
self.configuration = configuration
|
||||||
@@ -60,7 +65,12 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
- parameter migrationMappingProviders: an array of `SchemaMappingProviders` that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (as `InferredSchemaMappingProvider`) and may be omitted from the array.
|
- parameter migrationMappingProviders: an array of `SchemaMappingProviders` that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (as `InferredSchemaMappingProvider`) and may be omitted from the array.
|
||||||
- parameter localStorageOptions: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, tells the `DataStack` how to setup the persistent store. Defaults to `.None`.
|
- parameter localStorageOptions: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, tells the `DataStack` how to setup the persistent store. Defaults to `.None`.
|
||||||
*/
|
*/
|
||||||
public init(fileName: String, configuration: ModelConfiguration = nil, migrationMappingProviders: [SchemaMappingProvider] = [], localStorageOptions: LocalStorageOptions = nil) {
|
public init(
|
||||||
|
fileName: String,
|
||||||
|
configuration: ModelConfiguration = nil,
|
||||||
|
migrationMappingProviders: [SchemaMappingProvider] = [],
|
||||||
|
localStorageOptions: LocalStorageOptions = nil
|
||||||
|
) {
|
||||||
|
|
||||||
self.fileURL = SQLiteStore.defaultRootDirectory
|
self.fileURL = SQLiteStore.defaultRootDirectory
|
||||||
.appendingPathComponent(fileName, isDirectory: false)
|
.appendingPathComponent(fileName, isDirectory: false)
|
||||||
@@ -91,7 +101,12 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
- parameter migrationMappingProviders: an array of `SchemaMappingProviders` that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (as `InferredSchemaMappingProvider`) and may be omitted from the array.
|
- parameter migrationMappingProviders: an array of `SchemaMappingProviders` that provides the complete mapping models for custom migrations. All lightweight inferred mappings and/or migration mappings provided by *xcmappingmodel files are automatically used as fallback (as `InferredSchemaMappingProvider`) and may be omitted from the array.
|
||||||
- parameter localStorageOptions: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, tells the `DataStack` how to setup the persistent store. Defaults to `.None`.
|
- parameter localStorageOptions: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, tells the `DataStack` how to setup the persistent store. Defaults to `.None`.
|
||||||
*/
|
*/
|
||||||
public static func legacy(fileName: String, configuration: ModelConfiguration = nil, migrationMappingProviders: [SchemaMappingProvider] = [], localStorageOptions: LocalStorageOptions = nil) -> SQLiteStore {
|
public static func legacy(
|
||||||
|
fileName: String,
|
||||||
|
configuration: ModelConfiguration = nil,
|
||||||
|
migrationMappingProviders: [SchemaMappingProvider] = [],
|
||||||
|
localStorageOptions: LocalStorageOptions = nil
|
||||||
|
) -> SQLiteStore {
|
||||||
|
|
||||||
return SQLiteStore(
|
return SQLiteStore(
|
||||||
fileURL: SQLiteStore.legacyDefaultRootDirectory
|
fileURL: SQLiteStore.legacyDefaultRootDirectory
|
||||||
@@ -192,7 +207,9 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
/**
|
/**
|
||||||
The options dictionary for the specified `LocalStorageOptions`
|
The options dictionary for the specified `LocalStorageOptions`
|
||||||
*/
|
*/
|
||||||
public func dictionary(forOptions options: LocalStorageOptions) -> [AnyHashable: Any]? {
|
public func dictionary(
|
||||||
|
forOptions options: LocalStorageOptions
|
||||||
|
) -> [AnyHashable: Any]? {
|
||||||
|
|
||||||
if options == .none {
|
if options == .none {
|
||||||
|
|
||||||
@@ -211,7 +228,9 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
/**
|
/**
|
||||||
Called by the `DataStack` to perform checkpoint operations on the storage. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE to force a checkpoint.
|
Called by the `DataStack` to perform checkpoint operations on the storage. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE to force a checkpoint.
|
||||||
*/
|
*/
|
||||||
public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws {
|
public func cs_finalizeStorageAndWait(
|
||||||
|
soureModelHint: NSManagedObjectModel
|
||||||
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
_ = try withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: soureModelHint)) { (coordinator: NSPersistentStoreCoordinator) in
|
_ = try withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: soureModelHint)) { (coordinator: NSPersistentStoreCoordinator) in
|
||||||
|
|
||||||
@@ -230,9 +249,15 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
/**
|
/**
|
||||||
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
|
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
|
||||||
*/
|
*/
|
||||||
public func cs_eraseStorageAndWait(metadata: [String: Any], soureModelHint: NSManagedObjectModel?) throws {
|
public func cs_eraseStorageAndWait(
|
||||||
|
metadata: [String: Any],
|
||||||
|
soureModelHint: NSManagedObjectModel?
|
||||||
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
func deleteFiles(storeURL: URL, extraFiles: [String] = []) throws {
|
func deleteFiles(
|
||||||
|
storeURL: URL,
|
||||||
|
extraFiles: [String] = []
|
||||||
|
) throws(any Swift.Error) {
|
||||||
|
|
||||||
let fileManager = FileManager.default
|
let fileManager = FileManager.default
|
||||||
let extraFiles: [String] = [
|
let extraFiles: [String] = [
|
||||||
@@ -264,6 +289,7 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
}
|
}
|
||||||
DispatchQueue.global(qos: .background).async {
|
DispatchQueue.global(qos: .background).async {
|
||||||
|
|
||||||
|
let fileManager = FileManager.default
|
||||||
_ = try? fileManager.removeItem(at: temporaryFileURL)
|
_ = try? fileManager.removeItem(at: temporaryFileURL)
|
||||||
extraTemporaryFiles.forEach({ _ = try? fileManager.removeItem(atPath: $0) })
|
extraTemporaryFiles.forEach({ _ = try? fileManager.removeItem(atPath: $0) })
|
||||||
}
|
}
|
||||||
@@ -276,7 +302,7 @@ public final class SQLiteStore: LocalStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let fileURL = self.fileURL
|
let fileURL = self.fileURL
|
||||||
try autoreleasepool {
|
try Internals.autoreleasepool {
|
||||||
|
|
||||||
if let soureModel = soureModelHint ?? NSManagedObjectModel.mergedModel(from: nil, forStoreMetadata: metadata) {
|
if let soureModel = soureModelHint ?? NSManagedObjectModel.mergedModel(from: nil, forStoreMetadata: metadata) {
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,13 @@ public final class SchemaHistory: ExpressibleByArrayLiteral {
|
|||||||
- parameter xcodeDataModeld: a tuple returned from the `XcodeDataModelSchema.from(modelName:bundle:migrationChain:)` method.
|
- parameter xcodeDataModeld: a tuple returned from the `XcodeDataModelSchema.from(modelName:bundle:migrationChain:)` method.
|
||||||
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
||||||
*/
|
*/
|
||||||
public convenience init(_ xcodeDataModeld: (allSchema: [XcodeDataModelSchema], currentModelVersion: ModelVersion), migrationChain: MigrationChain = nil) {
|
public convenience init(
|
||||||
|
_ xcodeDataModeld: (
|
||||||
|
allSchema: [XcodeDataModelSchema],
|
||||||
|
currentModelVersion: ModelVersion
|
||||||
|
),
|
||||||
|
migrationChain: MigrationChain = nil
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(
|
self.init(
|
||||||
allSchema: xcodeDataModeld.allSchema,
|
allSchema: xcodeDataModeld.allSchema,
|
||||||
@@ -73,7 +79,12 @@ public final class SchemaHistory: ExpressibleByArrayLiteral {
|
|||||||
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
||||||
- parameter exactCurrentModelVersion: an optional string to explicitly select the current model version string. This is useful if the `DataStack` should load a non-latest model version (usually to prepare data before migration). If not provided, the current model version will be computed from the `MigrationChain`.
|
- parameter exactCurrentModelVersion: an optional string to explicitly select the current model version string. This is useful if the `DataStack` should load a non-latest model version (usually to prepare data before migration). If not provided, the current model version will be computed from the `MigrationChain`.
|
||||||
*/
|
*/
|
||||||
public convenience init(_ schema: DynamicSchema, _ otherSchema: DynamicSchema..., migrationChain: MigrationChain = nil, exactCurrentModelVersion: String? = nil) {
|
public convenience init(
|
||||||
|
_ schema: DynamicSchema,
|
||||||
|
_ otherSchema: DynamicSchema...,
|
||||||
|
migrationChain: MigrationChain = nil,
|
||||||
|
exactCurrentModelVersion: String? = nil
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(
|
self.init(
|
||||||
allSchema: [schema] + otherSchema,
|
allSchema: [schema] + otherSchema,
|
||||||
@@ -88,7 +99,11 @@ public final class SchemaHistory: ExpressibleByArrayLiteral {
|
|||||||
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
||||||
- parameter exactCurrentModelVersion: an optional string to explicitly select the current model version string. This is useful if the `DataStack` should load a non-latest model version (usually to prepare data before migration). If not provided, the current model version will be computed from the `MigrationChain`.
|
- parameter exactCurrentModelVersion: an optional string to explicitly select the current model version string. This is useful if the `DataStack` should load a non-latest model version (usually to prepare data before migration). If not provided, the current model version will be computed from the `MigrationChain`.
|
||||||
*/
|
*/
|
||||||
public required init(allSchema: [DynamicSchema], migrationChain: MigrationChain = nil, exactCurrentModelVersion: String? = nil) {
|
public required init(
|
||||||
|
allSchema: [DynamicSchema],
|
||||||
|
migrationChain: MigrationChain = nil,
|
||||||
|
exactCurrentModelVersion: String? = nil
|
||||||
|
) {
|
||||||
|
|
||||||
if allSchema.isEmpty {
|
if allSchema.isEmpty {
|
||||||
|
|
||||||
|
|||||||
@@ -37,5 +37,12 @@ public protocol SchemaMappingProvider {
|
|||||||
/**
|
/**
|
||||||
Do not call directly.
|
Do not call directly.
|
||||||
*/
|
*/
|
||||||
func cs_createMappingModel(from sourceSchema: DynamicSchema, to destinationSchema: DynamicSchema, storage: LocalStorage) throws -> (mappingModel: NSMappingModel, migrationType: MigrationType)
|
func cs_createMappingModel(
|
||||||
|
from sourceSchema: DynamicSchema,
|
||||||
|
to destinationSchema: DynamicSchema,
|
||||||
|
storage: LocalStorage
|
||||||
|
) throws(CoreStoreError) -> (
|
||||||
|
mappingModel: NSMappingModel,
|
||||||
|
migrationType: MigrationType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+148
-40
@@ -43,7 +43,9 @@ public protocol SelectResultType {}
|
|||||||
*/
|
*/
|
||||||
public protocol SelectAttributesResultType: SelectResultType {
|
public protocol SelectAttributesResultType: SelectResultType {
|
||||||
|
|
||||||
static func cs_fromQueryResultsNativeType(_ result: [Any]) -> [[String: Any]]
|
static func cs_fromQueryResultsNativeType(
|
||||||
|
_ result: [Any]
|
||||||
|
) -> [[String: Any]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,7 +76,9 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter keyPath: the attribute name
|
- parameter keyPath: the attribute name
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
||||||
*/
|
*/
|
||||||
public static func attribute(_ keyPath: KeyPathString) -> SelectTerm<O> {
|
public static func attribute(
|
||||||
|
_ keyPath: KeyPathString
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return ._attribute(keyPath)
|
return ._attribute(keyPath)
|
||||||
}
|
}
|
||||||
@@ -91,7 +95,10 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
||||||
*/
|
*/
|
||||||
public static func average(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func average(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "average:",
|
function: "average:",
|
||||||
@@ -113,7 +120,10 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for a count query
|
- returns: a `SelectTerm` to a `Select` clause for a count query
|
||||||
*/
|
*/
|
||||||
public static func count(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func count(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "count:",
|
function: "count:",
|
||||||
@@ -135,7 +145,10 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func maximum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func maximum(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "max:",
|
function: "max:",
|
||||||
@@ -157,7 +170,10 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func minimum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func minimum(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "min:",
|
function: "min:",
|
||||||
@@ -179,7 +195,10 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func sum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func sum(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return ._aggregate(
|
return ._aggregate(
|
||||||
function: "sum:",
|
function: "sum:",
|
||||||
@@ -202,7 +221,9 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func objectID(as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func objectID(
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return ._identity(
|
return ._identity(
|
||||||
alias: alias ?? "objectID",
|
alias: alias ?? "objectID",
|
||||||
@@ -231,7 +252,10 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
|
|
||||||
// MARK: Equatable
|
// MARK: Equatable
|
||||||
|
|
||||||
public static func == (lhs: SelectTerm<O>, rhs: SelectTerm<O>) -> Bool {
|
public static func == (
|
||||||
|
lhs: SelectTerm<O>,
|
||||||
|
rhs: SelectTerm<O>
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
switch (lhs, rhs) {
|
switch (lhs, rhs) {
|
||||||
|
|
||||||
@@ -284,8 +308,18 @@ public enum SelectTerm<O: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
|||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
case _attribute(KeyPathString)
|
case _attribute(KeyPathString)
|
||||||
case _aggregate(function: String, keyPath: KeyPathString, alias: String, nativeType: NSAttributeType)
|
|
||||||
case _identity(alias: String, nativeType: NSAttributeType)
|
case _aggregate(
|
||||||
|
function: String,
|
||||||
|
keyPath: KeyPathString,
|
||||||
|
alias: String,
|
||||||
|
nativeType: NSAttributeType
|
||||||
|
)
|
||||||
|
|
||||||
|
case _identity(
|
||||||
|
alias: String,
|
||||||
|
nativeType: NSAttributeType
|
||||||
|
)
|
||||||
|
|
||||||
internal var keyPathString: String {
|
internal var keyPathString: String {
|
||||||
|
|
||||||
@@ -308,7 +342,9 @@ extension SelectTerm where O: NSManagedObject {
|
|||||||
- parameter keyPath: the attribute name
|
- parameter keyPath: the attribute name
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
||||||
*/
|
*/
|
||||||
public static func attribute<V>(_ keyPath: KeyPath<O, V>) -> SelectTerm<O> {
|
public static func attribute<V>(
|
||||||
|
_ keyPath: KeyPath<O, V>
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return self.attribute(keyPath._kvcKeyPathString!)
|
return self.attribute(keyPath._kvcKeyPathString!)
|
||||||
}
|
}
|
||||||
@@ -319,9 +355,15 @@ extension SelectTerm where O: NSManagedObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
||||||
*/
|
*/
|
||||||
public static func average<V>(_ keyPath: KeyPath<O, V>, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func average<V>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return self.average(keyPath._kvcKeyPathString!, as: alias)
|
return self.average(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -330,9 +372,15 @@ extension SelectTerm where O: NSManagedObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for a count query
|
- returns: a `SelectTerm` to a `Select` clause for a count query
|
||||||
*/
|
*/
|
||||||
public static func count<V>(_ keyPath: KeyPath<O, V>, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func count<V>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return self.count(keyPath._kvcKeyPathString!, as: alias)
|
return self.count(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,9 +389,15 @@ extension SelectTerm where O: NSManagedObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func maximum<V>(_ keyPath: KeyPath<O, V>, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func maximum<V>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return self.maximum(keyPath._kvcKeyPathString!, as: alias)
|
return self.maximum(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -352,9 +406,15 @@ extension SelectTerm where O: NSManagedObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func minimum<V>(_ keyPath: KeyPath<O, V>, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func minimum<V>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return self.minimum(keyPath._kvcKeyPathString!, as: alias)
|
return self.minimum(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -363,9 +423,15 @@ extension SelectTerm where O: NSManagedObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func sum<V>(_ keyPath: KeyPath<O, V>, as alias: KeyPathString? = nil) -> SelectTerm<O> {
|
public static func sum<V>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> {
|
||||||
|
|
||||||
return self.sum(keyPath._kvcKeyPathString!, as: alias)
|
return self.sum(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,7 +445,9 @@ extension SelectTerm where O: CoreStoreObject {
|
|||||||
- parameter keyPath: the attribute name
|
- parameter keyPath: the attribute name
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
||||||
*/
|
*/
|
||||||
public static func attribute<K: AttributeKeyPathStringConvertible>(_ keyPath: KeyPath<O, K>) -> SelectTerm<O> where K.ObjectType == O {
|
public static func attribute<K: AttributeKeyPathStringConvertible>(
|
||||||
|
_ keyPath: KeyPath<O, K>
|
||||||
|
) -> SelectTerm<O> where K.ObjectType == O {
|
||||||
|
|
||||||
return self.attribute(O.meta[keyPath: keyPath].cs_keyPathString)
|
return self.attribute(O.meta[keyPath: keyPath].cs_keyPathString)
|
||||||
}
|
}
|
||||||
@@ -390,9 +458,15 @@ extension SelectTerm where O: CoreStoreObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
||||||
*/
|
*/
|
||||||
public static func average<K: AttributeKeyPathStringConvertible>(_ keyPath: KeyPath<O, K>, as alias: KeyPathString? = nil) -> SelectTerm<O> where K.ObjectType == O{
|
public static func average<K: AttributeKeyPathStringConvertible>(
|
||||||
|
_ keyPath: KeyPath<O, K>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> where K.ObjectType == O{
|
||||||
|
|
||||||
return self.average(O.meta[keyPath: keyPath].cs_keyPathString, as: alias)
|
return self.average(
|
||||||
|
O.meta[keyPath: keyPath].cs_keyPathString,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -401,10 +475,15 @@ extension SelectTerm where O: CoreStoreObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for a count query
|
- returns: a `SelectTerm` to a `Select` clause for a count query
|
||||||
*/
|
*/
|
||||||
public static func count<K: AttributeKeyPathStringConvertible>(_ keyPath: KeyPath<O,
|
public static func count<K: AttributeKeyPathStringConvertible>(
|
||||||
K>, as alias: KeyPathString? = nil) -> SelectTerm<O> where K.ObjectType == O {
|
_ keyPath: KeyPath<O, K>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> where K.ObjectType == O {
|
||||||
|
|
||||||
return self.count(O.meta[keyPath: keyPath].cs_keyPathString, as: alias)
|
return self.count(
|
||||||
|
O.meta[keyPath: keyPath].cs_keyPathString,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -413,10 +492,15 @@ extension SelectTerm where O: CoreStoreObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func maximum<K: AttributeKeyPathStringConvertible>(_ keyPath: KeyPath<O,
|
public static func maximum<K: AttributeKeyPathStringConvertible>(
|
||||||
K>, as alias: KeyPathString? = nil) -> SelectTerm<O> where K.ObjectType == O {
|
_ keyPath: KeyPath<O, K>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> where K.ObjectType == O {
|
||||||
|
|
||||||
return self.maximum(O.meta[keyPath: keyPath].cs_keyPathString, as: alias)
|
return self.maximum(
|
||||||
|
O.meta[keyPath: keyPath].cs_keyPathString,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -425,9 +509,15 @@ extension SelectTerm where O: CoreStoreObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func minimum<K: AttributeKeyPathStringConvertible>(_ keyPath: KeyPath<O, K>, as alias: KeyPathString? = nil) -> SelectTerm<O> where K.ObjectType == O {
|
public static func minimum<K: AttributeKeyPathStringConvertible>(
|
||||||
|
_ keyPath: KeyPath<O, K>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> where K.ObjectType == O {
|
||||||
|
|
||||||
return self.minimum(O.meta[keyPath: keyPath].cs_keyPathString, as: alias)
|
return self.minimum(
|
||||||
|
O.meta[keyPath: keyPath].cs_keyPathString,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -436,9 +526,15 @@ extension SelectTerm where O: CoreStoreObject {
|
|||||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||||
*/
|
*/
|
||||||
public static func sum<K: AttributeKeyPathStringConvertible>(_ keyPath: KeyPath<O, K>, as alias: KeyPathString? = nil) -> SelectTerm<O> where K.ObjectType == O {
|
public static func sum<K: AttributeKeyPathStringConvertible>(
|
||||||
|
_ keyPath: KeyPath<O, K>,
|
||||||
|
as alias: KeyPathString? = nil
|
||||||
|
) -> SelectTerm<O> where K.ObjectType == O {
|
||||||
|
|
||||||
return self.sum(O.meta[keyPath: keyPath].cs_keyPathString, as: alias)
|
return self.sum(
|
||||||
|
O.meta[keyPath: keyPath].cs_keyPathString,
|
||||||
|
as: alias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,7 +575,10 @@ public struct Select<O: DynamicObject, T: SelectResultType>: SelectClause, Hasha
|
|||||||
- parameter selectTerm: a `SelectTerm`
|
- parameter selectTerm: a `SelectTerm`
|
||||||
- parameter selectTerms: a series of `SelectTerm`s
|
- parameter selectTerms: a series of `SelectTerm`s
|
||||||
*/
|
*/
|
||||||
public init(_ selectTerm: SelectTerm<O>, _ selectTerms: SelectTerm<O>...) {
|
public init(
|
||||||
|
_ selectTerm: SelectTerm<O>,
|
||||||
|
_ selectTerms: SelectTerm<O>...
|
||||||
|
) {
|
||||||
|
|
||||||
self.selectTerms = [selectTerm] + selectTerms
|
self.selectTerms = [selectTerm] + selectTerms
|
||||||
}
|
}
|
||||||
@@ -489,7 +588,9 @@ public struct Select<O: DynamicObject, T: SelectResultType>: SelectClause, Hasha
|
|||||||
|
|
||||||
- parameter selectTerms: a series of `SelectTerm`s
|
- parameter selectTerms: a series of `SelectTerm`s
|
||||||
*/
|
*/
|
||||||
public init(_ selectTerms: [SelectTerm<O>]) {
|
public init(
|
||||||
|
_ selectTerms: [SelectTerm<O>]
|
||||||
|
) {
|
||||||
|
|
||||||
self.selectTerms = selectTerms
|
self.selectTerms = selectTerms
|
||||||
}
|
}
|
||||||
@@ -497,7 +598,10 @@ public struct Select<O: DynamicObject, T: SelectResultType>: SelectClause, Hasha
|
|||||||
|
|
||||||
// MARK: Equatable
|
// MARK: Equatable
|
||||||
|
|
||||||
public static func == <T1, T2>(lhs: Select<O, T1>, rhs: Select<O, T2>) -> Bool {
|
public static func == <T1, T2>(
|
||||||
|
lhs: Select<O, T1>,
|
||||||
|
rhs: Select<O, T2>
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
return lhs.selectTerms == rhs.selectTerms
|
return lhs.selectTerms == rhs.selectTerms
|
||||||
}
|
}
|
||||||
@@ -521,7 +625,9 @@ public struct Select<O: DynamicObject, T: SelectResultType>: SelectClause, Hasha
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSDictionary>) {
|
internal func applyToFetchRequest(
|
||||||
|
_ fetchRequest: NSFetchRequest<NSDictionary>
|
||||||
|
) {
|
||||||
|
|
||||||
fetchRequest.includesPendingChanges = false
|
fetchRequest.includesPendingChanges = false
|
||||||
fetchRequest.resultType = .dictionaryResultType
|
fetchRequest.resultType = .dictionaryResultType
|
||||||
@@ -661,7 +767,9 @@ extension NSDictionary: SelectAttributesResultType {
|
|||||||
|
|
||||||
// MARK: SelectAttributesResultType
|
// MARK: SelectAttributesResultType
|
||||||
|
|
||||||
public static func cs_fromQueryResultsNativeType(_ result: [Any]) -> [[String : Any]] {
|
public static func cs_fromQueryResultsNativeType(
|
||||||
|
_ result: [Any]
|
||||||
|
) -> [[String : Any]] {
|
||||||
|
|
||||||
return result as! [[String: Any]]
|
return result as! [[String: Any]]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,17 +139,24 @@ public protocol LocalStorage: StorageInterface {
|
|||||||
/**
|
/**
|
||||||
The options dictionary for the specified `LocalStorageOptions`
|
The options dictionary for the specified `LocalStorageOptions`
|
||||||
*/
|
*/
|
||||||
func dictionary(forOptions options: LocalStorageOptions) -> [AnyHashable: Any]?
|
func dictionary(
|
||||||
|
forOptions options: LocalStorageOptions
|
||||||
|
) -> [AnyHashable: Any]?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Called by the `DataStack` to perform checkpoint operations on the storage. (SQLite stores for example, can convert the database's WAL journaling mode to DELETE to force a checkpoint)
|
Called by the `DataStack` to perform checkpoint operations on the storage. (SQLite stores for example, can convert the database's WAL journaling mode to DELETE to force a checkpoint)
|
||||||
*/
|
*/
|
||||||
func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws
|
func cs_finalizeStorageAndWait(
|
||||||
|
soureModelHint: NSManagedObjectModel
|
||||||
|
) throws(any Swift.Error)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Called by the `DataStack` to perform actual deletion of the store file from disk. **Do not call directly!** The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (SQLite stores for example, can convert WAL journaling mode to DELETE before deleting)
|
Called by the `DataStack` to perform actual deletion of the store file from disk. **Do not call directly!** The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (SQLite stores for example, can convert WAL journaling mode to DELETE before deleting)
|
||||||
*/
|
*/
|
||||||
func cs_eraseStorageAndWait(metadata: [String: Any], soureModelHint: NSManagedObjectModel?) throws
|
func cs_eraseStorageAndWait(
|
||||||
|
metadata: [String: Any],
|
||||||
|
soureModelHint: NSManagedObjectModel?
|
||||||
|
) throws(any Swift.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension LocalStorage {
|
extension LocalStorage {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
```
|
```
|
||||||
- Important: Always use plain `try` on a `cancel()` call. Never use `try?` or `try!`. Using `try?` will swallow the cancellation and the transaction will proceed to commit as normal. Using `try!` will crash the app as `cancel()` will *always* throw an error.
|
- Important: Always use plain `try` on a `cancel()` call. Never use `try?` or `try!`. Using `try?` will swallow the cancellation and the transaction will proceed to commit as normal. Using `try!` will crash the app as `cancel()` will *always* throw an error.
|
||||||
*/
|
*/
|
||||||
public func cancel() throws -> Never {
|
public func cancel() throws(CoreStoreError) -> Never {
|
||||||
|
|
||||||
throw CoreStoreError.userCancelled
|
throw CoreStoreError.userCancelled
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
|
||||||
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
|
||||||
*/
|
*/
|
||||||
public override func create<O>(_ into: Into<O>) -> O {
|
public override func create<O>(
|
||||||
|
_ into: Into<O>
|
||||||
|
) -> O {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -71,7 +73,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited
|
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
||||||
*/
|
*/
|
||||||
public override func edit<O: DynamicObject>(_ object: O?) -> O? {
|
public override func edit<O: DynamicObject>(
|
||||||
|
_ object: O?
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -88,7 +92,10 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||||
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
|
||||||
*/
|
*/
|
||||||
public override func edit<O>(_ into: Into<O>, _ objectID: NSManagedObjectID) -> O? {
|
public override func edit<O>(
|
||||||
|
_ into: Into<O>,
|
||||||
|
_ objectID: NSManagedObjectID
|
||||||
|
) -> O? {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -103,7 +110,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
- parameter objectIDs: the `NSManagedObjectID`s of the objects to delete
|
- parameter objectIDs: the `NSManagedObjectID`s of the objects to delete
|
||||||
*/
|
*/
|
||||||
public override func delete<S: Sequence>(objectIDs: S) where S.Iterator.Element: NSManagedObjectID {
|
public override func delete<S: Sequence>(
|
||||||
|
objectIDs: S
|
||||||
|
) where S.Iterator.Element: NSManagedObjectID {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -119,7 +128,10 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
- parameter object: the `ObjectRepresentation` representing an `NSManagedObject` or `CoreStoreObject` to be deleted
|
- parameter object: the `ObjectRepresentation` representing an `NSManagedObject` or `CoreStoreObject` to be deleted
|
||||||
- parameter objects: other `ObjectRepresentation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
- parameter objects: other `ObjectRepresentation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
||||||
*/
|
*/
|
||||||
public override func delete<O: ObjectRepresentation>(_ object: O?, _ objects: O?...) {
|
public override func delete<O: ObjectRepresentation>(
|
||||||
|
_ object: O?,
|
||||||
|
_ objects: O?...
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -134,7 +146,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
- parameter objects: the `ObjectRepresenation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
- parameter objects: the `ObjectRepresenation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
|
||||||
*/
|
*/
|
||||||
public override func delete<S: Sequence>(_ objects: S) where S.Iterator.Element: ObjectRepresentation {
|
public override func delete<S: Sequence>(
|
||||||
|
_ objects: S
|
||||||
|
) where S.Iterator.Element: ObjectRepresentation {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
@@ -162,7 +176,12 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func autoCommit(waitForMerge: Bool) -> (hasChanges: Bool, error: CoreStoreError?) {
|
internal func autoCommit(
|
||||||
|
waitForMerge: Bool
|
||||||
|
) -> (
|
||||||
|
hasChanges: Bool,
|
||||||
|
error: CoreStoreError?
|
||||||
|
) {
|
||||||
|
|
||||||
self.isCommitted = true
|
self.isCommitted = true
|
||||||
let result = self.context.saveSynchronously(
|
let result = self.context.saveSynchronously(
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ public final class UnsafeDataModelSchema: DynamicSchema {
|
|||||||
- parameter modelName: the model version, typically the file name of an *.xcdatamodeld file (without the file extension)
|
- parameter modelName: the model version, typically the file name of an *.xcdatamodeld file (without the file extension)
|
||||||
- parameter model: the `NSManagedObjectModel`
|
- parameter model: the `NSManagedObjectModel`
|
||||||
*/
|
*/
|
||||||
public required init(modelName: ModelVersion, model: NSManagedObjectModel) {
|
public required init(
|
||||||
|
modelName: ModelVersion,
|
||||||
|
model: NSManagedObjectModel
|
||||||
|
) {
|
||||||
|
|
||||||
self.modelVersion = modelName
|
self.modelVersion = modelName
|
||||||
self.model = model
|
self.model = model
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter object: the `DynamicObject` to observe changes from
|
- parameter object: the `DynamicObject` to observe changes from
|
||||||
- returns: an `ObjectMonitor` that monitors changes to `object`
|
- returns: an `ObjectMonitor` that monitors changes to `object`
|
||||||
*/
|
*/
|
||||||
public func monitorObject<O: DynamicObject>(_ object: O) -> ObjectMonitor<O> {
|
public func monitorObject<O: DynamicObject>(
|
||||||
|
_ object: O
|
||||||
|
) -> ObjectMonitor<O> {
|
||||||
|
|
||||||
return .init(objectID: object.cs_id(), context: self.unsafeContext())
|
return .init(objectID: object.cs_id(), context: self.unsafeContext())
|
||||||
}
|
}
|
||||||
@@ -49,7 +51,10 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorList<O>(_ from: From<O>, _ fetchClauses: FetchClause...) -> ListMonitor<O> {
|
public func monitorList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> ListMonitor<O> {
|
||||||
|
|
||||||
return self.monitorList(from, fetchClauses)
|
return self.monitorList(from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -61,7 +66,10 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorList<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) -> ListMonitor<O> {
|
public func monitorList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> ListMonitor<O> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
fetchClauses.filter { $0 is OrderBy<O> }.count > 0,
|
fetchClauses.filter { $0 is OrderBy<O> }.count > 0,
|
||||||
@@ -96,7 +104,9 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
- returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
*/
|
*/
|
||||||
public func monitorList<B: FetchChainableBuilderType>(_ clauseChain: B) -> ListMonitor<B.ObjectType> {
|
public func monitorList<B: FetchChainableBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) -> ListMonitor<B.ObjectType> {
|
||||||
|
|
||||||
return self.monitorList(clauseChain.from, clauseChain.fetchClauses)
|
return self.monitorList(clauseChain.from, clauseChain.fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -108,7 +118,11 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorList<O>(createAsynchronously: @escaping (ListMonitor<O>) -> Void, _ from: From<O>, _ fetchClauses: FetchClause...) {
|
public func monitorList<O>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<O>) -> Void,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) {
|
||||||
|
|
||||||
self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -120,7 +134,11 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter from: a `From` clause indicating the entity type
|
- parameter from: a `From` clause indicating the entity type
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorList<O>(createAsynchronously: @escaping (ListMonitor<O>) -> Void, _ from: From<O>, _ fetchClauses: [FetchClause]) {
|
public func monitorList<O>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<O>) -> Void,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
fetchClauses.filter { $0 is OrderBy<O> }.count > 0,
|
fetchClauses.filter { $0 is OrderBy<O> }.count > 0,
|
||||||
@@ -155,7 +173,10 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
*/
|
*/
|
||||||
public func monitorList<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public func monitorList<B: FetchChainableBuilderType>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void,
|
||||||
|
_ clauseChain: B
|
||||||
|
) {
|
||||||
|
|
||||||
self.monitorList(
|
self.monitorList(
|
||||||
createAsynchronously: createAsynchronously,
|
createAsynchronously: createAsynchronously,
|
||||||
@@ -172,7 +193,11 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) -> ListMonitor<O> {
|
public func monitorSectionedList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) -> ListMonitor<O> {
|
||||||
|
|
||||||
return self.monitorSectionedList(from, sectionBy, fetchClauses)
|
return self.monitorSectionedList(from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -185,7 +210,11 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
- returns: a `ListMonitor` instance that monitors changes to the list
|
- returns: a `ListMonitor` instance that monitors changes to the list
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) -> ListMonitor<O> {
|
public func monitorSectionedList<O>(
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) -> ListMonitor<O> {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
fetchClauses.filter { $0 is OrderBy<O> }.count > 0,
|
fetchClauses.filter { $0 is OrderBy<O> }.count > 0,
|
||||||
@@ -216,7 +245,9 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
||||||
- returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType`
|
- returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType`
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<B: SectionMonitorBuilderType>(_ clauseChain: B) -> ListMonitor<B.ObjectType> {
|
public func monitorSectionedList<B: SectionMonitorBuilderType>(
|
||||||
|
_ clauseChain: B
|
||||||
|
) -> ListMonitor<B.ObjectType> {
|
||||||
|
|
||||||
return self.monitorSectionedList(
|
return self.monitorSectionedList(
|
||||||
clauseChain.from,
|
clauseChain.from,
|
||||||
@@ -233,7 +264,12 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<O>(createAsynchronously: @escaping (ListMonitor<O>) -> Void, _ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) {
|
public func monitorSectionedList<O>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<O>) -> Void,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: FetchClause...
|
||||||
|
) {
|
||||||
|
|
||||||
self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
|
||||||
}
|
}
|
||||||
@@ -246,7 +282,12 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
|
||||||
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<O>(createAsynchronously: @escaping (ListMonitor<O>) -> Void, _ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) {
|
public func monitorSectionedList<O>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<O>) -> Void,
|
||||||
|
_ from: From<O>,
|
||||||
|
_ sectionBy: SectionBy<O>,
|
||||||
|
_ fetchClauses: [FetchClause]
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
fetchClauses.filter { $0 is OrderBy<O> }.count > 0,
|
fetchClauses.filter { $0 is OrderBy<O> }.count > 0,
|
||||||
@@ -281,7 +322,10 @@ extension UnsafeDataTransaction {
|
|||||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
||||||
*/
|
*/
|
||||||
public func monitorSectionedList<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public func monitorSectionedList<B: SectionMonitorBuilderType>(
|
||||||
|
createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void,
|
||||||
|
_ clauseChain: B
|
||||||
|
) {
|
||||||
|
|
||||||
self.monitorSectionedList(
|
self.monitorSectionedList(
|
||||||
createAsynchronously: createAsynchronously,
|
createAsynchronously: createAsynchronously,
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
- parameter completion: the block executed after the save completes. Success or failure is reported by the optional `error` argument of the block.
|
- parameter completion: the block executed after the save completes. Success or failure is reported by the optional `error` argument of the block.
|
||||||
*/
|
*/
|
||||||
public func commit(_ completion: @escaping (_ error: CoreStoreError?) -> Void) {
|
public func commit(
|
||||||
|
_ completion: @escaping (_ error: CoreStoreError?) -> Void
|
||||||
|
) {
|
||||||
|
|
||||||
self.context.saveAsynchronously(
|
self.context.saveAsynchronously(
|
||||||
sourceIdentifier: self.sourceIdentifier,
|
sourceIdentifier: self.sourceIdentifier,
|
||||||
@@ -58,7 +60,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
- throws: a `CoreStoreError` value indicating the failure.
|
- throws: a `CoreStoreError` value indicating the failure.
|
||||||
*/
|
*/
|
||||||
public func commitAndWait() throws {
|
public func commitAndWait() throws(CoreStoreError) {
|
||||||
|
|
||||||
if case (_, let error?) = self.context.saveSynchronously(
|
if case (_, let error?) = self.context.saveSynchronously(
|
||||||
waitForMerge: true,
|
waitForMerge: true,
|
||||||
@@ -111,7 +113,9 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
|
|||||||
- parameter closure: the closure where changes can be made prior to the flush
|
- parameter closure: the closure where changes can be made prior to the flush
|
||||||
- throws: an error thrown from `closure`, or an error thrown by Core Data (usually validation errors or conflict errors)
|
- throws: an error thrown from `closure`, or an error thrown by Core Data (usually validation errors or conflict errors)
|
||||||
*/
|
*/
|
||||||
public func flush(closure: () throws -> Void) rethrows {
|
public func flush(
|
||||||
|
closure: () throws(any Swift.Error) -> Void
|
||||||
|
) rethrows {
|
||||||
|
|
||||||
try closure()
|
try closure()
|
||||||
self.context.processPendingChanges()
|
self.context.processPendingChanges()
|
||||||
|
|||||||
@@ -118,9 +118,15 @@ extension Where {
|
|||||||
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~<O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCKeyPathValue>(_ lhs: KeyPath<O, D>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<Where<O>.SingleTarget, V> {
|
public func ~<O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCKeyPathValue>(
|
||||||
|
_ lhs: KeyPath<O, D>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<Where<O>.SingleTarget, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,9 +135,15 @@ public func ~<O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCKeyPat
|
|||||||
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
let owner = dataStack.fetchOne(From<Pet>().where((\.master ~ \.name) == "John"))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCKeyPathValue>(_ lhs: KeyPath<O, D?>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<Where<O>.SingleTarget, V> {
|
public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCKeyPathValue>(
|
||||||
|
_ lhs: KeyPath<O, D?>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<Where<O>.SingleTarget, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,9 +152,15 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCKeyPa
|
|||||||
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(_ lhs: KeyPath<O, D>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(
|
||||||
|
_ lhs: KeyPath<O, D>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,9 +169,15 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCToMan
|
|||||||
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
let happyPets = dataStack.fetchAll(From<Pet>().where((\.master ~ \.pets).count() > 1))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(_ lhs: KeyPath<O, D?>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(
|
||||||
|
_ lhs: KeyPath<O, D?>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,9 +186,15 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, V: AllowedObjectiveCToMan
|
|||||||
let johnsSonInLaw = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.name) == "John"))
|
let johnsSonInLaw = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.name) == "John"))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCKeyPathValue>(_ lhs: Where<O>.Expression<T, D>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<T, V> {
|
public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCKeyPathValue>(
|
||||||
|
_ lhs: Where<O>.Expression<T, D>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<T, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,9 +203,15 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCKe
|
|||||||
let johnsSonInLaw = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.name) == "John"))
|
let johnsSonInLaw = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.name) == "John"))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCKeyPathValue>(_ lhs: Where<O>.Expression<T, D?>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<T, V> {
|
public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCKeyPathValue>(
|
||||||
|
_ lhs: Where<O>.Expression<T, D?>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<T, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,9 +220,15 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCKe
|
|||||||
let spouseHasSiblings = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.children).count() > 0))
|
let spouseHasSiblings = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.children).count() > 0))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(_ lhs: Where<O>.Expression<T, D>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(
|
||||||
|
_ lhs: Where<O>.Expression<T, D>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,9 +237,15 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCTo
|
|||||||
let spouseHasSiblings = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.children).count() > 0))
|
let spouseHasSiblings = dataStack.fetchOne(From<Person>().where((\.spouse ~ \.father ~ \.children).count() > 0))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(_ lhs: Where<O>.Expression<T, D?>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCToManyRelationshipKeyPathValue>(
|
||||||
|
_ lhs: Where<O>.Expression<T, D?>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,9 +254,15 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, T, V: AllowedObjectiveCTo
|
|||||||
let spousesWithBadNamingSense = dataStack.fetchAll(From<Person>().where((\.spouse ~ \.pets ~ \.name).any() == "Spot"))
|
let spousesWithBadNamingSense = dataStack.fetchAll(From<Person>().where((\.spouse ~ \.pets ~ \.name).any() == "Spot"))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: NSManagedObject, D: NSManagedObject, T, C: AllowedObjectiveCToManyRelationshipKeyPathValue, V: AllowedObjectiveCKeyPathValue>(_ lhs: Where<O>.Expression<T, C>, _ rhs: KeyPath<D, V>) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
public func ~ <O: NSManagedObject, D: NSManagedObject, T, C: AllowedObjectiveCToManyRelationshipKeyPathValue, V: AllowedObjectiveCKeyPathValue>(
|
||||||
|
_ lhs: Where<O>.Expression<T, C>,
|
||||||
|
_ rhs: KeyPath<D, V>
|
||||||
|
) -> Where<O>.Expression<Where<O>.CollectionTarget, V> {
|
||||||
|
|
||||||
return .init(lhs.cs_keyPathString, rhs.cs_keyPathString)
|
return .init(
|
||||||
|
lhs.cs_keyPathString,
|
||||||
|
rhs.cs_keyPathString
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -220,7 +274,10 @@ public func ~ <O: NSManagedObject, D: NSManagedObject, T, C: AllowedObjectiveCTo
|
|||||||
let owner = dataStack.fetchOne(From<Pet>().where((\.$master ~ \.$name) == "John"))
|
let owner = dataStack.fetchOne(From<Pet>().where((\.$master ~ \.$name) == "John"))
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
public func ~ <O: CoreStoreObject, D: FieldRelationshipToOneType, K: KeyPathStringConvertible>(_ lhs: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ rhs: KeyPath<D.DestinationObjectType, K>) -> Where<O>.Expression<Where<O>.SingleTarget, K.DestinationValueType> where K.ObjectType == D.DestinationObjectType {
|
public func ~ <O: CoreStoreObject, D: FieldRelationshipToOneType, K: KeyPathStringConvertible>(
|
||||||
|
_ lhs: KeyPath<O, FieldContainer<O>.Relationship<D>>,
|
||||||
|
_ rhs: KeyPath<D.DestinationObjectType, K>
|
||||||
|
) -> Where<O>.Expression<Where<O>.SingleTarget, K.DestinationValueType> where K.ObjectType == D.DestinationObjectType {
|
||||||
|
|
||||||
return .init(
|
return .init(
|
||||||
O.meta[keyPath: lhs].cs_keyPathString,
|
O.meta[keyPath: lhs].cs_keyPathString,
|
||||||
|
|||||||
+289
-67
@@ -37,32 +37,58 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
/**
|
/**
|
||||||
Combines two `Where` predicates together using `AND` operator
|
Combines two `Where` predicates together using `AND` operator
|
||||||
*/
|
*/
|
||||||
public static func && (left: Where<O>, right: Where<O>) -> Where<O> {
|
public static func && (
|
||||||
|
left: Where<O>,
|
||||||
|
right: Where<O>
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate]))
|
return Where<O>(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .and,
|
||||||
|
subpredicates: [left.predicate, right.predicate]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Combines two `Where` predicates together using `OR` operator
|
Combines two `Where` predicates together using `OR` operator
|
||||||
*/
|
*/
|
||||||
public static func || (left: Where<O>, right: Where<O>) -> Where<O> {
|
public static func || (
|
||||||
|
left: Where<O>,
|
||||||
|
right: Where<O>
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate]))
|
return Where<O>(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .or,
|
||||||
|
subpredicates: [left.predicate, right.predicate]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Inverts the predicate of a `Where` clause using `NOT` operator
|
Inverts the predicate of a `Where` clause using `NOT` operator
|
||||||
*/
|
*/
|
||||||
public static prefix func ! (clause: Where<O>) -> Where<O> {
|
public static prefix func ! (
|
||||||
|
clause: Where<O>
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
return Where<O>(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate]))
|
return Where<O>(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .not,
|
||||||
|
subpredicates: [clause.predicate]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Combines two `Where` predicates together using `AND` operator.
|
Combines two `Where` predicates together using `AND` operator.
|
||||||
- returns: `left` if `right` is `nil`, otherwise equivalent to `(left && right)`
|
- returns: `left` if `right` is `nil`, otherwise equivalent to `(left && right)`
|
||||||
*/
|
*/
|
||||||
public static func &&? (left: Where<O>, right: Where<O>?) -> Where<O> {
|
public static func &&? (
|
||||||
|
left: Where<O>,
|
||||||
|
right: Where<O>?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
if let right = right {
|
if let right = right {
|
||||||
|
|
||||||
@@ -75,7 +101,10 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
Combines two `Where` predicates together using `AND` operator.
|
Combines two `Where` predicates together using `AND` operator.
|
||||||
- returns: `right` if `left` is `nil`, otherwise equivalent to `(left && right)`
|
- returns: `right` if `left` is `nil`, otherwise equivalent to `(left && right)`
|
||||||
*/
|
*/
|
||||||
public static func &&? (left: Where<O>?, right: Where<O>) -> Where<O> {
|
public static func &&? (
|
||||||
|
left: Where<O>?,
|
||||||
|
right: Where<O>
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
if let left = left {
|
if let left = left {
|
||||||
|
|
||||||
@@ -88,7 +117,10 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
Combines two `Where` predicates together using `OR` operator.
|
Combines two `Where` predicates together using `OR` operator.
|
||||||
- returns: `left` if `right` is `nil`, otherwise equivalent to `(left || right)`
|
- returns: `left` if `right` is `nil`, otherwise equivalent to `(left || right)`
|
||||||
*/
|
*/
|
||||||
public static func ||? (left: Where<O>, right: Where<O>?) -> Where<O> {
|
public static func ||? (
|
||||||
|
left: Where<O>,
|
||||||
|
right: Where<O>?
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
if let right = right {
|
if let right = right {
|
||||||
|
|
||||||
@@ -101,7 +133,10 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
Combines two `Where` predicates together using `OR` operator.
|
Combines two `Where` predicates together using `OR` operator.
|
||||||
- returns: `right` if `left` is `nil`, otherwise equivalent to `(left || right)`
|
- returns: `right` if `left` is `nil`, otherwise equivalent to `(left || right)`
|
||||||
*/
|
*/
|
||||||
public static func ||? (left: Where<O>?, right: Where<O>) -> Where<O> {
|
public static func ||? (
|
||||||
|
left: Where<O>?,
|
||||||
|
right: Where<O>
|
||||||
|
) -> Where<O> {
|
||||||
|
|
||||||
if let left = left {
|
if let left = left {
|
||||||
|
|
||||||
@@ -123,7 +158,9 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
|
|
||||||
- parameter clause: the existing `Where` clause.
|
- parameter clause: the existing `Where` clause.
|
||||||
*/
|
*/
|
||||||
public init(_ clause: Where<O>) {
|
public init(
|
||||||
|
_ clause: Where<O>
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(clause.predicate)
|
self.init(clause.predicate)
|
||||||
}
|
}
|
||||||
@@ -133,7 +170,9 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
|
|
||||||
- parameter value: the boolean value for the predicate
|
- parameter value: the boolean value for the predicate
|
||||||
*/
|
*/
|
||||||
public init(_ value: Bool) {
|
public init(
|
||||||
|
_ value: Bool
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(NSPredicate(value: value))
|
self.init(NSPredicate(value: value))
|
||||||
}
|
}
|
||||||
@@ -144,7 +183,10 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter format: the format string for the predicate
|
- parameter format: the format string for the predicate
|
||||||
- parameter args: the arguments for `format`
|
- parameter args: the arguments for `format`
|
||||||
*/
|
*/
|
||||||
public init(_ format: String, _ args: Any...) {
|
public init(
|
||||||
|
_ format: String,
|
||||||
|
_ args: Any...
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(NSPredicate(format: format, argumentArray: args))
|
self.init(NSPredicate(format: format, argumentArray: args))
|
||||||
}
|
}
|
||||||
@@ -155,7 +197,10 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter format: the format string for the predicate
|
- parameter format: the format string for the predicate
|
||||||
- parameter argumentArray: the arguments for `format`
|
- parameter argumentArray: the arguments for `format`
|
||||||
*/
|
*/
|
||||||
public init(_ format: String, argumentArray: [Any]?) {
|
public init(
|
||||||
|
_ format: String,
|
||||||
|
argumentArray: [Any]?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(NSPredicate(format: format, argumentArray: argumentArray))
|
self.init(NSPredicate(format: format, argumentArray: argumentArray))
|
||||||
}
|
}
|
||||||
@@ -166,7 +211,10 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter null: the arguments for the `==` operator
|
- parameter null: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init(_ keyPath: KeyPathString, isEqualTo null: Void?) {
|
public init(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isEqualTo null: Void?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) == nil"))
|
self.init(NSPredicate(format: "\(keyPath) == nil"))
|
||||||
}
|
}
|
||||||
@@ -177,7 +225,10 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<V: FieldStorableType>(_ keyPath: KeyPathString, isEqualTo value: V) {
|
public init<V: FieldStorableType>(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isEqualTo value: V
|
||||||
|
) {
|
||||||
|
|
||||||
var nilPredicate: NSPredicate {
|
var nilPredicate: NSPredicate {
|
||||||
|
|
||||||
@@ -227,16 +278,28 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
@_disfavoredOverload
|
@_disfavoredOverload
|
||||||
public init<U: QueryableAttributeType>(_ keyPath: KeyPathString, isEqualTo value: U?) {
|
public init<U: QueryableAttributeType>(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isEqualTo value: U?
|
||||||
|
) {
|
||||||
|
|
||||||
switch value {
|
switch value {
|
||||||
|
|
||||||
case nil,
|
case nil,
|
||||||
is NSNull:
|
is NSNull:
|
||||||
self.init(NSPredicate(format: "\(keyPath) == nil"))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) == nil"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
case let value?:
|
case let value?:
|
||||||
self.init(NSPredicate(format: "\(keyPath) == %@", argumentArray: [value.cs_toQueryableNativeType()]))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) == %@",
|
||||||
|
argumentArray: [value.cs_toQueryableNativeType()]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,15 +309,27 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter object: the arguments for the `==` operator
|
- parameter object: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<Other: DynamicObject>(_ keyPath: KeyPathString, isEqualTo object: Other?) {
|
public init<Other: DynamicObject>(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isEqualTo object: Other?
|
||||||
|
) {
|
||||||
|
|
||||||
switch object {
|
switch object {
|
||||||
|
|
||||||
case nil:
|
case nil:
|
||||||
self.init(NSPredicate(format: "\(keyPath) == nil"))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) == nil"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
case let object?:
|
case let object?:
|
||||||
self.init(NSPredicate(format: "\(keyPath) == %@", argumentArray: [object.cs_id()]))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) == %@",
|
||||||
|
argumentArray: [object.cs_id()]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,9 +339,17 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter objectID: the arguments for the `==` operator
|
- parameter objectID: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init(_ keyPath: KeyPathString, isEqualTo objectID: NSManagedObjectID) {
|
public init(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isEqualTo objectID: NSManagedObjectID
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) == %@", argumentArray: [objectID]))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) == %@",
|
||||||
|
argumentArray: [objectID]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -275,9 +358,17 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<S: Sequence>(_ keyPath: KeyPathString, isMemberOf list: S) where S.Iterator.Element: FieldStorableType {
|
public init<S: Sequence>(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element: FieldStorableType {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toFieldStoredNativeType() }) as NSArray))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) IN %@",
|
||||||
|
list.map({ $0.cs_toFieldStoredNativeType() }) as NSArray
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -287,9 +378,17 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
@_disfavoredOverload
|
@_disfavoredOverload
|
||||||
public init<S: Sequence>(_ keyPath: KeyPathString, isMemberOf list: S) where S.Iterator.Element: QueryableAttributeType {
|
public init<S: Sequence>(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element: QueryableAttributeType {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryableNativeType() }) as NSArray))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) IN %@",
|
||||||
|
list.map({ $0.cs_toQueryableNativeType() }) as NSArray
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,9 +397,17 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<S: Sequence>(_ keyPath: KeyPathString, isMemberOf list: S) where S.Iterator.Element: DynamicObject {
|
public init<S: Sequence>(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element: DynamicObject {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_id() }) as NSArray))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) IN %@",
|
||||||
|
list.map({ $0.cs_id() }) as NSArray
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -309,9 +416,17 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<S: Sequence>(_ keyPath: KeyPathString, isMemberOf list: S) where S.Iterator.Element: NSManagedObjectID {
|
public init<S: Sequence>(
|
||||||
|
_ keyPath: KeyPathString,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element: NSManagedObjectID {
|
||||||
|
|
||||||
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0 }) as NSArray))
|
self.init(
|
||||||
|
NSPredicate(
|
||||||
|
format: "\(keyPath) IN %@",
|
||||||
|
list.map({ $0 }) as NSArray
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -332,7 +447,9 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
|
|
||||||
// MARK: FetchClause, QueryClause, DeleteClause
|
// MARK: FetchClause, QueryClause, DeleteClause
|
||||||
|
|
||||||
public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
public func applyToFetchRequest<ResultType>(
|
||||||
|
_ fetchRequest: NSFetchRequest<ResultType>
|
||||||
|
) {
|
||||||
|
|
||||||
if let predicate = fetchRequest.predicate, predicate != self.predicate {
|
if let predicate = fetchRequest.predicate, predicate != self.predicate {
|
||||||
|
|
||||||
@@ -348,7 +465,10 @@ public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
|||||||
|
|
||||||
// MARK: Equatable
|
// MARK: Equatable
|
||||||
|
|
||||||
public static func == (lhs: Where, rhs: Where) -> Bool {
|
public static func == (
|
||||||
|
lhs: Self,
|
||||||
|
rhs: Self
|
||||||
|
) -> Bool {
|
||||||
|
|
||||||
return lhs.predicate == rhs.predicate
|
return lhs.predicate == rhs.predicate
|
||||||
}
|
}
|
||||||
@@ -373,9 +493,15 @@ extension Where where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter null: the arguments for the `==` operator
|
- parameter null: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<O, V>, isEqualTo null: Void?) {
|
public init<V: QueryableAttributeType>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
isEqualTo null: Void?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: null)
|
self.init(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -384,9 +510,15 @@ extension Where where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter null: the arguments for the `==` operator
|
- parameter null: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<D: DynamicObject>(_ keyPath: KeyPath<O, D>, isEqualTo null: Void?) {
|
public init<D: DynamicObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
isEqualTo null: Void?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: null)
|
self.init(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -395,9 +527,15 @@ extension Where where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<O, V>, isEqualTo value: V?) {
|
public init<V: QueryableAttributeType>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
isEqualTo value: V?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: value)
|
self.init(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -406,9 +544,15 @@ extension Where where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<D: DynamicObject>(_ keyPath: KeyPath<O, D>, isEqualTo value: D?) {
|
public init<D: DynamicObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
isEqualTo value: D?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: value)
|
self.init(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -417,9 +561,15 @@ extension Where where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter objectID: the arguments for the `==` operator
|
- parameter objectID: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<D: DynamicObject>(_ keyPath: KeyPath<O, D>, isEqualTo objectID: NSManagedObjectID) {
|
public init<D: DynamicObject>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
isEqualTo objectID: NSManagedObjectID
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
self.init(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isEqualTo: objectID
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -428,9 +578,15 @@ extension Where where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<V: QueryableAttributeType, S: Sequence>(_ keyPath: KeyPath<O, V>, isMemberOf list: S) where S.Iterator.Element == V {
|
public init<V: QueryableAttributeType, S: Sequence>(
|
||||||
|
_ keyPath: KeyPath<O, V>,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element == V {
|
||||||
|
|
||||||
self.init(keyPath._kvcKeyPathString!, isMemberOf: list)
|
self.init(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: list
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -439,9 +595,15 @@ extension Where where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<D: DynamicObject, S: Sequence>(_ keyPath: KeyPath<O, D>, isMemberOf list: S) where S.Iterator.Element == D {
|
public init<D: DynamicObject, S: Sequence>(
|
||||||
|
_ keyPath: KeyPath<O, D>,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element == D {
|
||||||
|
|
||||||
self.init(keyPath._kvcKeyPathString!, isMemberOf: list)
|
self.init(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: list
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -450,9 +612,15 @@ extension Where where O: NSManagedObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<D: DynamicObject, S: Sequence>(_ keyPath: KeyPath<D, O>, isMemberOf list: S) where S.Iterator.Element: NSManagedObjectID {
|
public init<D: DynamicObject, S: Sequence>(
|
||||||
|
_ keyPath: KeyPath<D, O>,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element: NSManagedObjectID {
|
||||||
|
|
||||||
self.init(keyPath._kvcKeyPathString!, isMemberOf: list)
|
self.init(
|
||||||
|
keyPath._kvcKeyPathString!,
|
||||||
|
isMemberOf: list
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,9 +635,15 @@ extension Where where O: CoreStoreObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, isEqualTo value: V) {
|
public init<V>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
isEqualTo value: V
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: value)
|
self.init(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -478,9 +652,15 @@ extension Where where O: CoreStoreObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter value: the arguments for the `==` operator
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<V: FieldRelationshipToOneType>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<V>>, isEqualTo value: V.DestinationObjectType?) {
|
public init<V: FieldRelationshipToOneType>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<V>>,
|
||||||
|
isEqualTo value: V.DestinationObjectType?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: value)
|
self.init(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isEqualTo: value
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -489,9 +669,15 @@ extension Where where O: CoreStoreObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter null: the arguments for the `==` operator
|
- parameter null: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, isEqualTo null: Void?) {
|
public init<V>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
isEqualTo null: Void?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: null)
|
self.init(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isEqualTo: null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -500,9 +686,15 @@ extension Where where O: CoreStoreObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter null: the arguments for the `==` operator
|
- parameter null: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init<V: FieldRelationshipToOneType>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<V>>, isEqualTo null: Void?) {
|
public init<V: FieldRelationshipToOneType>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<V>>,
|
||||||
|
isEqualTo null: Void?
|
||||||
|
) {
|
||||||
|
|
||||||
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: null)
|
self.init(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isEqualTo: null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -511,9 +703,15 @@ extension Where where O: CoreStoreObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<V, S: Sequence>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, isMemberOf list: S) where S.Iterator.Element == V {
|
public init<V, S: Sequence>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element == V {
|
||||||
|
|
||||||
self.init(O.meta[keyPath: keyPath].keyPath, isMemberOf: list)
|
self.init(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isMemberOf: list
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -522,9 +720,15 @@ extension Where where O: CoreStoreObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<V: FieldRelationshipToOneType, S: Sequence>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<V>>, isMemberOf list: S) where S.Iterator.Element == V.DestinationObjectType {
|
public init<V: FieldRelationshipToOneType, S: Sequence>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<V>>,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element == V.DestinationObjectType {
|
||||||
|
|
||||||
self.init(O.meta[keyPath: keyPath].keyPath, isMemberOf: list)
|
self.init(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isMemberOf: list
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -533,9 +737,15 @@ extension Where where O: CoreStoreObject {
|
|||||||
- parameter keyPath: the keyPath to compare with
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter list: the sequence to check membership of
|
- parameter list: the sequence to check membership of
|
||||||
*/
|
*/
|
||||||
public init<V: FieldRelationshipToOneType, S: Sequence>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<V>>, isMemberOf list: S) where S.Iterator.Element: NSManagedObjectID {
|
public init<V: FieldRelationshipToOneType, S: Sequence>(
|
||||||
|
_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<V>>,
|
||||||
|
isMemberOf list: S
|
||||||
|
) where S.Iterator.Element: NSManagedObjectID {
|
||||||
|
|
||||||
self.init(O.meta[keyPath: keyPath].keyPath, isMemberOf: list)
|
self.init(
|
||||||
|
O.meta[keyPath: keyPath].keyPath,
|
||||||
|
isMemberOf: list
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -543,7 +753,9 @@ extension Where where O: CoreStoreObject {
|
|||||||
|
|
||||||
- parameter condition: closure that returns the `Where` clause
|
- parameter condition: closure that returns the `Where` clause
|
||||||
*/
|
*/
|
||||||
public init(_ condition: (O) -> Where<O>) {
|
public init(
|
||||||
|
_ condition: (O) -> Where<O>
|
||||||
|
) {
|
||||||
|
|
||||||
self = condition(O.meta)
|
self = condition(O.meta)
|
||||||
}
|
}
|
||||||
@@ -559,7 +771,12 @@ extension Sequence where Iterator.Element: WhereClauseType {
|
|||||||
*/
|
*/
|
||||||
public func combinedByAnd() -> Where<Iterator.Element.ObjectType> {
|
public func combinedByAnd() -> Where<Iterator.Element.ObjectType> {
|
||||||
|
|
||||||
return Where(NSCompoundPredicate(type: .and, subpredicates: self.map({ $0.predicate })))
|
return Where(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .and,
|
||||||
|
subpredicates: self.map({ $0.predicate })
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -567,7 +784,12 @@ extension Sequence where Iterator.Element: WhereClauseType {
|
|||||||
*/
|
*/
|
||||||
public func combinedByOr() -> Where<Iterator.Element.ObjectType> {
|
public func combinedByOr() -> Where<Iterator.Element.ObjectType> {
|
||||||
|
|
||||||
return Where(NSCompoundPredicate(type: .or, subpredicates: self.map({ $0.predicate })))
|
return Where(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .or,
|
||||||
|
subpredicates: self.map({ $0.predicate })
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,35 +45,67 @@ extension WhereClauseType {
|
|||||||
Combines two `Where` predicates together using `AND` operator.
|
Combines two `Where` predicates together using `AND` operator.
|
||||||
- Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows AND'ing clauses of unrelated `DynamicObject` types.
|
- Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows AND'ing clauses of unrelated `DynamicObject` types.
|
||||||
*/
|
*/
|
||||||
public static func && <TWhere: WhereClauseType>(left: Self, right: TWhere) -> Where<Self.ObjectType> {
|
public static func && <TWhere: WhereClauseType>(
|
||||||
|
left: Self,
|
||||||
|
right: TWhere
|
||||||
|
) -> Where<Self.ObjectType> {
|
||||||
|
|
||||||
return .init(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate]))
|
return .init(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .and,
|
||||||
|
subpredicates: [left.predicate, right.predicate]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Combines two `Where` predicates together using `AND` operator.
|
Combines two `Where` predicates together using `AND` operator.
|
||||||
- Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows AND'ing clauses of unrelated `DynamicObject` types.
|
- Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows AND'ing clauses of unrelated `DynamicObject` types.
|
||||||
*/
|
*/
|
||||||
public static func && <TWhere: WhereClauseType>(left: TWhere, right: Self) -> Where<Self.ObjectType> {
|
public static func && <TWhere: WhereClauseType>(
|
||||||
|
left: TWhere,
|
||||||
|
right: Self
|
||||||
|
) -> Where<Self.ObjectType> {
|
||||||
|
|
||||||
return .init(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate]))
|
return .init(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .and,
|
||||||
|
subpredicates: [left.predicate, right.predicate]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Combines two `Where` predicates together using `OR` operator.
|
Combines two `Where` predicates together using `OR` operator.
|
||||||
- Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows OR'ing clauses of unrelated `DynamicObject` types.
|
- Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows OR'ing clauses of unrelated `DynamicObject` types.
|
||||||
*/
|
*/
|
||||||
public static func || <TWhere: WhereClauseType>(left: Self, right: TWhere) -> Where<Self.ObjectType> {
|
public static func || <TWhere: WhereClauseType>(
|
||||||
|
left: Self,
|
||||||
|
right: TWhere
|
||||||
|
) -> Where<Self.ObjectType> {
|
||||||
|
|
||||||
return .init(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate]))
|
return .init(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .or,
|
||||||
|
subpredicates: [left.predicate, right.predicate]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Combines two `Where` predicates together using `OR` operator.
|
Combines two `Where` predicates together using `OR` operator.
|
||||||
- Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows OR'ing clauses of unrelated `DynamicObject` types.
|
- Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows OR'ing clauses of unrelated `DynamicObject` types.
|
||||||
*/
|
*/
|
||||||
public static func || <TWhere: WhereClauseType>(left: TWhere, right: Self) -> Where<Self.ObjectType> {
|
public static func || <TWhere: WhereClauseType>(
|
||||||
|
left: TWhere,
|
||||||
|
right: Self
|
||||||
|
) -> Where<Self.ObjectType> {
|
||||||
|
|
||||||
return .init(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate]))
|
return .init(
|
||||||
|
NSCompoundPredicate(
|
||||||
|
type: .or,
|
||||||
|
subpredicates: [left.predicate, right.predicate]
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,14 @@ public final class XcodeDataModelSchema: DynamicSchema {
|
|||||||
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
|
||||||
- returns: a tuple containing all `XcodeDataModelSchema` for the models declared in the specified .xcdatamodeld file, and the current model version string declared or inferred from the file.
|
- returns: a tuple containing all `XcodeDataModelSchema` for the models declared in the specified .xcdatamodeld file, and the current model version string declared or inferred from the file.
|
||||||
*/
|
*/
|
||||||
public static func from(modelName: XcodeDataModelFileName, bundle: Bundle = Bundle.main, migrationChain: MigrationChain = nil) -> (allSchema: [XcodeDataModelSchema], currentModelVersion: ModelVersion) {
|
public static func from(
|
||||||
|
modelName: XcodeDataModelFileName,
|
||||||
|
bundle: Bundle = Bundle.main,
|
||||||
|
migrationChain: MigrationChain = nil
|
||||||
|
) -> (
|
||||||
|
allSchema: [XcodeDataModelSchema],
|
||||||
|
currentModelVersion: ModelVersion
|
||||||
|
) {
|
||||||
|
|
||||||
guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else {
|
guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else {
|
||||||
|
|
||||||
@@ -116,7 +123,10 @@ public final class XcodeDataModelSchema: DynamicSchema {
|
|||||||
- parameter modelName: the model version, typically the file name of an *.xcdatamodeld file (without the file extension)
|
- parameter modelName: the model version, typically the file name of an *.xcdatamodeld file (without the file extension)
|
||||||
- parameter bundle: the `Bundle` that contains the .xcdatamodeld's "momd" file. If not specified, the `Bundle.main` will be searched.
|
- parameter bundle: the `Bundle` that contains the .xcdatamodeld's "momd" file. If not specified, the `Bundle.main` will be searched.
|
||||||
*/
|
*/
|
||||||
public convenience init(modelName: ModelVersion, bundle: Bundle = Bundle.main) {
|
public convenience init(
|
||||||
|
modelName: ModelVersion,
|
||||||
|
bundle: Bundle = Bundle.main
|
||||||
|
) {
|
||||||
|
|
||||||
guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else {
|
guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else {
|
||||||
|
|
||||||
@@ -142,7 +152,10 @@ public final class XcodeDataModelSchema: DynamicSchema {
|
|||||||
- parameter modelName: the model version, typically the file name of an *.xcdatamodeld file (without the file extension)
|
- parameter modelName: the model version, typically the file name of an *.xcdatamodeld file (without the file extension)
|
||||||
- parameter modelVersionFileURL: the file URL that points to the .xcdatamodeld's "momd" file.
|
- parameter modelVersionFileURL: the file URL that points to the .xcdatamodeld's "momd" file.
|
||||||
*/
|
*/
|
||||||
public required init(modelName: ModelVersion, modelVersionFileURL: URL) {
|
public required init(
|
||||||
|
modelName: ModelVersion,
|
||||||
|
modelVersionFileURL: URL
|
||||||
|
) {
|
||||||
|
|
||||||
Internals.assert(
|
Internals.assert(
|
||||||
NSManagedObjectModel(contentsOf: modelVersionFileURL) != nil,
|
NSManagedObjectModel(contentsOf: modelVersionFileURL) != nil,
|
||||||
|
|||||||
@@ -56,7 +56,11 @@ public final class XcodeSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
- parameter destinationVersion: the destination model version for the mapping
|
- parameter destinationVersion: the destination model version for the mapping
|
||||||
- parameter mappingModelBundle: the `Bundle` that contains the xcmappingmodel file
|
- parameter mappingModelBundle: the `Bundle` that contains the xcmappingmodel file
|
||||||
*/
|
*/
|
||||||
public required init(from sourceVersion: ModelVersion, to destinationVersion: ModelVersion, mappingModelBundle: Bundle) {
|
public required init(
|
||||||
|
from sourceVersion: ModelVersion,
|
||||||
|
to destinationVersion: ModelVersion,
|
||||||
|
mappingModelBundle: Bundle
|
||||||
|
) {
|
||||||
|
|
||||||
self.sourceVersion = sourceVersion
|
self.sourceVersion = sourceVersion
|
||||||
self.destinationVersion = destinationVersion
|
self.destinationVersion = destinationVersion
|
||||||
@@ -85,7 +89,14 @@ public final class XcodeSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
|||||||
|
|
||||||
// MARK: SchemaMappingProvider
|
// MARK: SchemaMappingProvider
|
||||||
|
|
||||||
public func cs_createMappingModel(from sourceSchema: DynamicSchema, to destinationSchema: DynamicSchema, storage: LocalStorage) throws -> (mappingModel: NSMappingModel, migrationType: MigrationType) {
|
public func cs_createMappingModel(
|
||||||
|
from sourceSchema: DynamicSchema,
|
||||||
|
to destinationSchema: DynamicSchema,
|
||||||
|
storage: LocalStorage
|
||||||
|
) throws(CoreStoreError) -> (
|
||||||
|
mappingModel: NSMappingModel,
|
||||||
|
migrationType: MigrationType
|
||||||
|
) {
|
||||||
|
|
||||||
let sourceModel = sourceSchema.rawModel()
|
let sourceModel = sourceSchema.rawModel()
|
||||||
let destinationModel = destinationSchema.rawModel()
|
let destinationModel = destinationSchema.rawModel()
|
||||||
|
|||||||
Reference in New Issue
Block a user