Where clauses are now more strict with the argument types

This commit is contained in:
John Estropia
2017-02-17 10:47:38 +09:00
parent 03973790a8
commit d2fd03c1f0
5 changed files with 439 additions and 277 deletions

View File

@@ -101,20 +101,44 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
- parameter keyPath: the keyPath to compare with
- parameter value: the arguments for the `==` operator
*/
public init(_ keyPath: KeyPath, isEqualTo value: Any?) {
public init(_ keyPath: KeyPath, isEqualTo value: CoreDataNativeType?) {
self.init(value == nil
? NSPredicate(format: "\(keyPath) == nil")
: NSPredicate(format: "\(keyPath) == %@", argumentArray: [value!]))
}
/**
Initializes a `Where` clause that compares equality
- parameter keyPath: the keyPath to compare with
- parameter value: the arguments for the `==` operator
*/
public init<T: CoreStoreSupportedAttributeType>(_ keyPath: KeyPath, isEqualTo value: T?) {
self.init(value == nil
? NSPredicate(format: "\(keyPath) == nil")
: NSPredicate(format: "\(keyPath) == %@", argumentArray: [value!.cs_toNativeType()]))
}
/**
Initializes a `Where` clause that compares membership
- parameter keyPath: the keyPath to compare with
- parameter list: the array to check membership of
*/
public init(_ keyPath: KeyPath, isMemberOf list: [Any]) {
public init(_ keyPath: KeyPath, isMemberOf list: [CoreDataNativeType]) {
self.init(NSPredicate(format: "\(keyPath) IN %@", list))
}
/**
Initializes a `Where` clause that compares membership
- parameter keyPath: the keyPath to compare with
- parameter list: the array to check membership of
*/
public init<T: CoreStoreSupportedAttributeType>(_ keyPath: KeyPath, isMemberOf list: [T]) {
self.init(NSPredicate(format: "\(keyPath) IN %@", list))
}
@@ -125,7 +149,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
- parameter keyPath: the keyPath to compare with
- parameter list: the sequence to check membership of
*/
public init<S: Sequence>(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: Any {
public init<S: Sequence>(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: CoreStoreSupportedAttributeType {
self.init(NSPredicate(format: "\(keyPath) IN %@", Array(list) as NSArray))
}