mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-14 21:23:43 +01:00
WIP: KeyPath utilities for all clauses
This commit is contained in:
@@ -332,7 +332,7 @@ public extension Where where D: NSManagedObject {
|
||||
*/
|
||||
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<D, V>, isEqualTo value: Void?) {
|
||||
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) == nil"))
|
||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,7 +343,7 @@ public extension Where where D: NSManagedObject {
|
||||
*/
|
||||
public init<O: DynamicObject>(_ keyPath: KeyPath<D, O>, isEqualTo value: Void?) {
|
||||
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) == nil"))
|
||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,15 +354,7 @@ public extension Where where D: NSManagedObject {
|
||||
*/
|
||||
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<D, V>, isEqualTo value: V?) {
|
||||
|
||||
switch value {
|
||||
|
||||
case nil,
|
||||
is NSNull:
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) == nil"))
|
||||
|
||||
case let value?:
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) == %@", argumentArray: [value.cs_toQueryableNativeType()]))
|
||||
}
|
||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,15 +365,7 @@ public extension Where where D: NSManagedObject {
|
||||
*/
|
||||
public init<O: DynamicObject>(_ keyPath: KeyPath<D, O>, isEqualTo value: O?) {
|
||||
|
||||
switch value {
|
||||
|
||||
case nil,
|
||||
is NSNull:
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) == nil"))
|
||||
|
||||
case let value?:
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) == %@", argumentArray: [value.cs_id()]))
|
||||
}
|
||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,7 +376,7 @@ public extension Where where D: NSManagedObject {
|
||||
*/
|
||||
public init<O: DynamicObject>(_ keyPath: KeyPath<D, O>, isEqualTo objectID: NSManagedObjectID) {
|
||||
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) == %@", argumentArray: [objectID]))
|
||||
self.init(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,7 +387,7 @@ public extension Where where D: NSManagedObject {
|
||||
*/
|
||||
public init<V: QueryableAttributeType, S: Sequence>(_ keyPath: KeyPath<D, V>, isMemberOf list: S) where S.Iterator.Element == V {
|
||||
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) IN %@", list.map({ $0.cs_toQueryableNativeType() }) as NSArray))
|
||||
self.init(keyPath._kvcKeyPathString!, isMemberOf: list)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,7 +398,7 @@ public extension Where where D: NSManagedObject {
|
||||
*/
|
||||
public init<O: DynamicObject, S: Sequence>(_ keyPath: KeyPath<D, O>, isMemberOf list: S) where S.Iterator.Element == O {
|
||||
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) IN %@", list.map({ $0.cs_id() }) as NSArray))
|
||||
self.init(keyPath._kvcKeyPathString!, isMemberOf: list)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,7 +409,123 @@ public extension Where where D: NSManagedObject {
|
||||
*/
|
||||
public init<O: DynamicObject, S: Sequence>(_ keyPath: KeyPath<D, O>, isMemberOf list: S) where S.Iterator.Element: NSManagedObjectID {
|
||||
|
||||
self.init(NSPredicate(format: "\(keyPath._kvcKeyPathString!) IN %@", list.map({ $0 }) as NSArray))
|
||||
self.init(keyPath._kvcKeyPathString!, isMemberOf: list)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Where where D: CoreStoreObject
|
||||
|
||||
public extension Where where D: CoreStoreObject {
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares equality to `nil`
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter value: the arguments for the `==` operator
|
||||
*/
|
||||
public init<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, isEqualTo value: Void?) {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares equality to `nil`
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter value: the arguments for the `==` operator
|
||||
*/
|
||||
public init<O>(_ keyPath: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, isEqualTo value: Void?) {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares equality
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter value: the arguments for the `==` operator
|
||||
*/
|
||||
public init<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<V>>, isEqualTo value: V?) {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares equality
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter value: the arguments for the `==` operator
|
||||
*/
|
||||
public init<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, isEqualTo value: V?) {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares equality
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter value: the arguments for the `==` operator
|
||||
*/
|
||||
public init<O>(_ keyPath: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, isEqualTo value: O?) {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares equality
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter objectID: the arguments for the `==` operator
|
||||
*/
|
||||
public init<O>(_ keyPath: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, isEqualTo objectID: NSManagedObjectID) {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: objectID)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares membership
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter list: the sequence to check membership of
|
||||
*/
|
||||
public init<V, S: Sequence>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<V>>, isMemberOf list: S) where S.Iterator.Element == V {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isMemberOf: list)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares membership
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter list: the sequence to check membership of
|
||||
*/
|
||||
public init<V, S: Sequence>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, isMemberOf list: S) where S.Iterator.Element == V {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isMemberOf: list)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares membership
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter list: the sequence to check membership of
|
||||
*/
|
||||
public init<O, S: Sequence>(_ keyPath: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, isMemberOf list: S) where S.Iterator.Element == O {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isMemberOf: list)
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes a `Where` clause that compares membership
|
||||
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter list: the sequence to check membership of
|
||||
*/
|
||||
public init<O, S: Sequence>(_ keyPath: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, isMemberOf list: S) where S.Iterator.Element: NSManagedObjectID {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isMemberOf: list)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user