Unify generic labeling

This commit is contained in:
John Estropia
2019-10-22 16:16:47 +09:00
parent 3d8bdf1cf3
commit 80166a42bb
37 changed files with 711 additions and 639 deletions

View File

@@ -36,37 +36,37 @@ infix operator ||? : LogicalConjunctionPrecedence
/**
The `Where` clause specifies the conditions for a fetch or a query.
*/
public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause, DeleteClause, Hashable {
public struct Where<O: DynamicObject>: WhereClauseType, FetchClause, QueryClause, DeleteClause, Hashable {
/**
Combines two `Where` predicates together using `AND` operator
*/
public static func && (left: Where<D>, right: Where<D>) -> Where<D> {
public static func && (left: Where<O>, right: Where<O>) -> Where<O> {
return Where<D>(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
*/
public static func || (left: Where<D>, right: Where<D>) -> Where<D> {
public static func || (left: Where<O>, right: Where<O>) -> Where<O> {
return Where<D>(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
*/
public static prefix func ! (clause: Where<D>) -> Where<D> {
public static prefix func ! (clause: Where<O>) -> Where<O> {
return Where<D>(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate]))
return Where<O>(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate]))
}
/**
Combines two `Where` predicates together using `AND` operator.
- returns: `left` if `right` is `nil`, otherwise equivalent to `(left && right)`
*/
public static func &&? (left: Where<D>, right: Where<D>?) -> Where<D> {
public static func &&? (left: Where<O>, right: Where<O>?) -> Where<O> {
if let right = right {
@@ -79,7 +79,7 @@ public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause
Combines two `Where` predicates together using `AND` operator.
- returns: `right` if `left` is `nil`, otherwise equivalent to `(left && right)`
*/
public static func &&? (left: Where<D>?, right: Where<D>) -> Where<D> {
public static func &&? (left: Where<O>?, right: Where<O>) -> Where<O> {
if let left = left {
@@ -92,7 +92,7 @@ public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause
Combines two `Where` predicates together using `OR` operator.
- returns: `left` if `right` is `nil`, otherwise equivalent to `(left || right)`
*/
public static func ||? (left: Where<D>, right: Where<D>?) -> Where<D> {
public static func ||? (left: Where<O>, right: Where<O>?) -> Where<O> {
if let right = right {
@@ -105,7 +105,7 @@ public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause
Combines two `Where` predicates together using `OR` operator.
- returns: `right` if `left` is `nil`, otherwise equivalent to `(left || right)`
*/
public static func ||? (left: Where<D>?, right: Where<D>) -> Where<D> {
public static func ||? (left: Where<O>?, right: Where<O>) -> Where<O> {
if let left = left {
@@ -127,7 +127,7 @@ public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause
- parameter clause: the existing `Where` clause.
*/
public init(_ clause: Where<D>) {
public init(_ clause: Where<O>) {
self.init(clause.predicate)
}
@@ -200,7 +200,7 @@ public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause
- parameter keyPath: the keyPath to compare with
- parameter object: the arguments for the `==` operator
*/
public init<D: DynamicObject>(_ keyPath: KeyPathString, isEqualTo object: D?) {
public init<O: DynamicObject>(_ keyPath: KeyPathString, isEqualTo object: O?) {
switch object {
@@ -269,7 +269,7 @@ public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause
// MARK: WhereClauseType
public typealias ObjectType = D
public typealias ObjectType = O
// MARK: FetchClause, QueryClause, DeleteClause
@@ -302,12 +302,18 @@ public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause
hasher.combine(self.predicate)
}
// MARK: Deprecated
@available(*, deprecated, renamed: "O")
public typealias D = O
}
// MARK: - Where where D: NSManagedObject
// MARK: - Where where O: NSManagedObject
extension Where where D: NSManagedObject {
extension Where where O: NSManagedObject {
/**
Initializes a `Where` clause that compares equality to `nil`
@@ -315,7 +321,7 @@ extension Where where D: NSManagedObject {
- parameter keyPath: the keyPath to compare with
- parameter null: the arguments for the `==` operator
*/
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<D, V>, isEqualTo null: Void?) {
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<O, V>, isEqualTo null: Void?) {
self.init(keyPath._kvcKeyPathString!, isEqualTo: null)
}
@@ -326,7 +332,7 @@ extension Where where D: NSManagedObject {
- parameter keyPath: the keyPath to compare with
- parameter null: the arguments for the `==` operator
*/
public init<O: DynamicObject>(_ keyPath: KeyPath<D, O>, isEqualTo null: Void?) {
public init<D: DynamicObject>(_ keyPath: KeyPath<O, D>, isEqualTo null: Void?) {
self.init(keyPath._kvcKeyPathString!, isEqualTo: null)
}
@@ -337,7 +343,7 @@ extension Where where D: NSManagedObject {
- parameter keyPath: the keyPath to compare with
- parameter value: the arguments for the `==` operator
*/
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<D, V>, isEqualTo value: V?) {
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<O, V>, isEqualTo value: V?) {
self.init(keyPath._kvcKeyPathString!, isEqualTo: value)
}
@@ -348,7 +354,7 @@ extension Where where D: NSManagedObject {
- parameter keyPath: the keyPath to compare with
- parameter value: the arguments for the `==` operator
*/
public init<O: DynamicObject>(_ keyPath: KeyPath<D, O>, isEqualTo value: O?) {
public init<D: DynamicObject>(_ keyPath: KeyPath<O, D>, isEqualTo value: D?) {
self.init(keyPath._kvcKeyPathString!, isEqualTo: value)
}
@@ -359,7 +365,7 @@ extension Where where D: NSManagedObject {
- parameter keyPath: the keyPath to compare with
- parameter objectID: the arguments for the `==` operator
*/
public init<O: DynamicObject>(_ keyPath: KeyPath<D, O>, isEqualTo objectID: NSManagedObjectID) {
public init<D: DynamicObject>(_ keyPath: KeyPath<O, D>, isEqualTo objectID: NSManagedObjectID) {
self.init(keyPath._kvcKeyPathString!, isEqualTo: objectID)
}
@@ -370,7 +376,7 @@ extension Where where D: NSManagedObject {
- parameter keyPath: the keyPath to compare with
- parameter list: the sequence to check membership of
*/
public init<V: QueryableAttributeType, S: Sequence>(_ keyPath: KeyPath<D, 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)
}
@@ -381,7 +387,7 @@ extension Where where D: NSManagedObject {
- parameter keyPath: the keyPath to compare with
- parameter list: the sequence to check membership of
*/
public init<O: DynamicObject, S: Sequence>(_ keyPath: KeyPath<D, O>, isMemberOf list: S) where S.Iterator.Element == O {
public init<D: DynamicObject, S: Sequence>(_ keyPath: KeyPath<O, D>, isMemberOf list: S) where S.Iterator.Element == D {
self.init(keyPath._kvcKeyPathString!, isMemberOf: list)
}
@@ -392,16 +398,16 @@ extension Where where D: NSManagedObject {
- parameter keyPath: the keyPath to compare with
- parameter list: the sequence to check membership of
*/
public init<O: 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)
}
}
// MARK: - Where where D: CoreStoreObject
// MARK: - Where where O: CoreStoreObject
extension Where where D: CoreStoreObject {
extension Where where O: CoreStoreObject {
/**
Initializes a `Where` clause that compares equality to `nil`
@@ -409,9 +415,9 @@ extension Where where D: CoreStoreObject {
- parameter keyPath: the keyPath to compare with
- parameter null: the arguments for the `==` operator
*/
public init<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, isEqualTo null: Void?) {
public init<V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, isEqualTo null: Void?) {
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: null)
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: null)
}
/**
@@ -420,9 +426,9 @@ extension Where where D: CoreStoreObject {
- parameter keyPath: the keyPath to compare with
- parameter null: the arguments for the `==` operator
*/
public init<O>(_ keyPath: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, isEqualTo null: Void?) {
public init<D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, isEqualTo null: Void?) {
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: null)
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: null)
}
/**
@@ -431,9 +437,9 @@ extension Where where D: CoreStoreObject {
- 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?) {
public init<V>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, isEqualTo value: V?) {
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: value)
}
/**
@@ -442,9 +448,9 @@ extension Where where D: CoreStoreObject {
- 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?) {
public init<V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, isEqualTo value: V?) {
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: value)
}
/**
@@ -453,9 +459,9 @@ extension Where where D: CoreStoreObject {
- 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?) {
public init<D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, isEqualTo value: D?) {
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: value)
}
/**
@@ -464,9 +470,9 @@ extension Where where D: CoreStoreObject {
- 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) {
public init<D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, isEqualTo objectID: NSManagedObjectID) {
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: objectID)
self.init(O.meta[keyPath: keyPath].keyPath, isEqualTo: objectID)
}
/**
@@ -475,9 +481,9 @@ extension Where where D: CoreStoreObject {
- 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 {
public init<V, S: Sequence>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<V>>, isMemberOf list: S) where S.Iterator.Element == V {
self.init(D.meta[keyPath: keyPath].keyPath, isMemberOf: list)
self.init(O.meta[keyPath: keyPath].keyPath, isMemberOf: list)
}
/**
@@ -486,9 +492,9 @@ extension Where where D: CoreStoreObject {
- 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 {
public init<V, S: Sequence>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, isMemberOf list: S) where S.Iterator.Element == V {
self.init(D.meta[keyPath: keyPath].keyPath, isMemberOf: list)
self.init(O.meta[keyPath: keyPath].keyPath, isMemberOf: list)
}
/**
@@ -497,9 +503,9 @@ extension Where where D: CoreStoreObject {
- 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 {
public init<D, S: Sequence>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, isMemberOf list: S) where S.Iterator.Element == D {
self.init(D.meta[keyPath: keyPath].keyPath, isMemberOf: list)
self.init(O.meta[keyPath: keyPath].keyPath, isMemberOf: list)
}
/**
@@ -508,9 +514,9 @@ extension Where where D: CoreStoreObject {
- 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 {
public init<D, S: Sequence>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, isMemberOf list: S) where S.Iterator.Element: NSManagedObjectID {
self.init(D.meta[keyPath: keyPath].keyPath, isMemberOf: list)
self.init(O.meta[keyPath: keyPath].keyPath, isMemberOf: list)
}
/**
@@ -518,9 +524,9 @@ extension Where where D: CoreStoreObject {
- parameter condition: closure that returns the `Where` clause
*/
public init(_ condition: (D) -> Where<D>) {
public init(_ condition: (O) -> Where<O>) {
self = condition(D.meta)
self = condition(O.meta)
}
}