diff --git a/Sources/Fetching and Querying/Concrete Clauses/Where.swift b/Sources/Fetching and Querying/Concrete Clauses/Where.swift index 1ebe5b5..e3e2568 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/Where.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/Where.swift @@ -133,6 +133,25 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { } } + /** + Initializes a `Where` clause that compares equality + + - parameter keyPath: the keyPath to compare with + - parameter object: the arguments for the `==` operator + */ + public init(_ keyPath: KeyPath, isEqualTo object: T?) { + + switch object { + + case nil, + is NSNull: + self.init(NSPredicate(format: "\(keyPath) == nil")) + + case let object?: + self.init(NSPredicate(format: "\(keyPath) == %@", argumentArray: [object.objectID])) + } + } + /** Initializes a `Where` clause that compares membership @@ -144,6 +163,17 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryableNativeType() }) as NSArray)) } + /** + Initializes a `Where` clause that compares membership + + - parameter keyPath: the keyPath to compare with + - parameter list: the sequence to check membership of + */ + public init(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: NSManagedObject { + + self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.objectID }) as NSArray)) + } + /** Initializes a `Where` clause with an `NSPredicate`