extra extra type safety for attributes (fetching and importing)

This commit is contained in:
John Estropia
2017-02-17 14:13:16 +09:00
parent d2fd03c1f0
commit 9d5e04854a
10 changed files with 744 additions and 637 deletions

View File

@@ -70,3 +70,8 @@ extension NSManagedObject: CoreDataNativeType {}
// MARK: - NSManagedObjectID
extension NSManagedObjectID: CoreDataNativeType {}
// MARK: - NSNull
extension NSNull: CoreDataNativeType {}

View File

@@ -101,46 +101,17 @@ 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: CoreDataNativeType?) {
public init<T: CoreStoreQueryingAttributeType>(_ keyPath: KeyPath, isEqualTo value: T?) {
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: [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))
switch value {
case nil,
is NSNull:
self.init(NSPredicate(format: "\(keyPath) == nil"))
case let value?:
self.init(NSPredicate(format: "\(keyPath) == %@", argumentArray: [value.cs_toQueryingNativeType()]))
}
}
/**
@@ -149,9 +120,9 @@ 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: CoreStoreSupportedAttributeType {
public init<S: Sequence>(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: CoreStoreQueryingAttributeType {
self.init(NSPredicate(format: "\(keyPath) IN %@", Array(list) as NSArray))
self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryingNativeType() }) as NSArray))
}
/**

View File

@@ -0,0 +1,272 @@
//
// CoreStoreQueryingAttributeType.swift
// CoreStore
//
// Copyright © 2017 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreGraphics
import CoreData
// MARK: - CoreStoreQueryingAttributeType
public protocol CoreStoreQueryingAttributeType: Hashable {
associatedtype NativeTypeForQuerying: CoreDataNativeType
func cs_toQueryingNativeType() -> NativeTypeForQuerying
}
// MARK: - NSManagedObject
extension NSManagedObject: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSManagedObjectID
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self.objectID
}
}
// MARK: - NSManagedObjectID
extension NSManagedObjectID: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSManagedObjectID
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self
}
}
// MARK: - NSNumber
extension NSNumber: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self
}
}
// MARK: - NSString
extension NSString: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSString
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self
}
}
// MARK: - NSDate
extension NSDate: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSDate
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self
}
}
// MARK: - NSData
extension NSData: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSData
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self
}
}
// MARK: - Bool
extension Bool: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSNumber
}
}
// MARK: - Int16
extension Int16: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSNumber
}
}
// MARK: - Int32
extension Int32: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSNumber
}
}
// MARK: - Int64
extension Int64: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSNumber
}
}
// MARK: - Int
extension Int: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSNumber
}
}
// MARK: - Double
extension Double: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSNumber
}
}
// MARK: - Float
extension Float: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSNumber
}
}
// MARK: - CGFloat
extension CGFloat: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNumber
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSNumber
}
}
// MARK: - Date
extension Date: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSDate
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSDate
}
}
// MARK: - String
extension String: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSString
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSString
}
}
// MARK: - Data
extension Data: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSData
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self as NSData
}
}
// MARK: - NSNull
extension NSNull: CoreStoreQueryingAttributeType {
public typealias NativeTypeForQuerying = NSNull
public func cs_toQueryingNativeType() -> NativeTypeForQuerying {
return self
}
}

View File

@@ -1,372 +0,0 @@
//
// CoreStoreSupportedAttributeType.swift
// CoreStore
//
// Copyright © 2017 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreData
// MARK: - CoreStoreSupportedAttributeType
public protocol CoreStoreSupportedAttributeType: Hashable {
associatedtype CoreStoreNativeType: CoreDataNativeType
static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self?
func cs_toNativeType() -> CoreStoreNativeType
}
// MARK: - NSManagedObject
extension NSManagedObject: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSManagedObject
public class func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self? {
func forceCast<T: NSManagedObject>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self
}
}
// MARK: - NSNumber
extension NSNumber: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSNumber
public class func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self? {
func forceCast<T: NSNumber>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self
}
}
// MARK: - NSString
extension NSString: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSString
public class func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self? {
func forceCast<T: NSString>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self
}
}
// MARK: - NSDate
extension NSDate: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSDate
public class func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self? {
func forceCast<T: NSDate>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self
}
}
// MARK: - NSData
extension NSData: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSData
public class func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self? {
func forceCast<T: NSData>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self
}
}
// MARK: - NSSet
extension NSSet: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSSet
public class func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self? {
func forceCast<T: NSSet>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self
}
}
// MARK: - NSOrderedSet
extension NSOrderedSet: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSOrderedSet
public class func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self? {
func forceCast<T: NSOrderedSet>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self
}
}
// MARK: - Bool
extension Bool: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSNumber
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Bool? {
return value.boolValue
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSNumber
}
}
// MARK: - Int16
extension Int16: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSNumber
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int16? {
return value.int16Value
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSNumber
}
}
// MARK: - Int32
extension Int32: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSNumber
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int32? {
return value.int32Value
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSNumber
}
}
// MARK: - Int64
extension Int64: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSNumber
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int64? {
return value.int64Value
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSNumber
}
}
// MARK: - Double
extension Double: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSNumber
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Double? {
return value.doubleValue
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSNumber
}
}
// MARK: - Float
extension Float: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSNumber
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Float? {
return value.floatValue
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSNumber
}
}
// MARK: - Date
extension Date: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSDate
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Date? {
return value as Date
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSDate
}
}
// MARK: - String
extension String: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSString
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> String? {
return value as String
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSString
}
}
// MARK: - Data
extension Data: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSData
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Data? {
return value as Data
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSData
}
}
// MARK: - Set
extension Set: CoreStoreSupportedAttributeType {
public typealias CoreStoreNativeType = NSSet
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Set? {
return value as? Set
}
public func cs_toNativeType() -> CoreStoreNativeType {
return self as NSSet
}
}

View File

@@ -0,0 +1,288 @@
//
// CoreStoreUniqueIDAttributeType.swift
// CoreStore
//
// Copyright © 2017 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreData
// MARK: - CoreStoreUniqueIDAttributeType
public protocol CoreStoreUniqueIDAttributeType: CoreStoreQueryingAttributeType {
associatedtype NativeTypeForUniqueID: CoreDataNativeType
static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Self?
func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID
}
// MARK: - NSNumber
extension NSNumber: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSNumber
public class func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Self? {
func forceCast<T: NSNumber>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self
}
}
// MARK: - NSString
extension NSString: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSString
public class func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Self? {
func forceCast<T: NSString>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self
}
}
// MARK: - NSDate
extension NSDate: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSDate
public class func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Self? {
func forceCast<T: NSDate>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self
}
}
// MARK: - NSData
extension NSData: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSData
public class func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Self? {
func forceCast<T: NSData>(_ value: Any) -> T? {
return value as? T
}
return forceCast(value)
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self
}
}
// MARK: - Bool
extension Bool: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSNumber
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Bool? {
return value.boolValue
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSNumber
}
}
// MARK: - Int16
extension Int16: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSNumber
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Int16? {
return value.int16Value
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSNumber
}
}
// MARK: - Int32
extension Int32: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSNumber
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Int32? {
return value.int32Value
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSNumber
}
}
// MARK: - Int64
extension Int64: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSNumber
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Int64? {
return value.int64Value
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSNumber
}
}
// MARK: - Double
extension Double: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSNumber
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Double? {
return value.doubleValue
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSNumber
}
}
// MARK: - Float
extension Float: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSNumber
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Float? {
return value.floatValue
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSNumber
}
}
// MARK: - Date
extension Date: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSDate
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Date? {
return value as Date
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSDate
}
}
// MARK: - String
extension String: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSString
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> String? {
return value as String
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSString
}
}
// MARK: - Data
extension Data: CoreStoreUniqueIDAttributeType {
public typealias NativeTypeForUniqueID = NSData
public static func cs_fromUniqueIDNativeType(_ value: NativeTypeForUniqueID) -> Data? {
return value as Data
}
public func cs_toUniqueIDNativeType() -> NativeTypeForUniqueID {
return self as NSData
}
}

View File

@@ -59,7 +59,7 @@ public protocol ImportableUniqueObject: ImportableObject {
/**
The data type for the entity's unique ID attribute
*/
associatedtype UniqueIDType: CoreStoreSupportedAttributeType
associatedtype UniqueIDType: CoreStoreUniqueIDAttributeType
/**
The keyPath to the entity's unique ID attribute
@@ -192,14 +192,14 @@ public extension ImportableUniqueObject where Self: NSManagedObject {
get {
return UniqueIDType.cs_fromNativeType(
self.value(forKey: type(of: self).uniqueIDKeyPath) as! UniqueIDType.CoreStoreNativeType
return UniqueIDType.cs_fromUniqueIDNativeType(
self.value(forKey: type(of: self).uniqueIDKeyPath) as! UniqueIDType.NativeTypeForUniqueID
)!
}
set {
self.setValue(
newValue.cs_toNativeType(),
newValue.cs_toUniqueIDNativeType(),
forKey: type(of: self).uniqueIDKeyPath
)
}

View File

@@ -87,7 +87,9 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
@objc
public convenience init(keyPath: KeyPath, isEqualTo value: CoreDataNativeType?) {
self.init(Where(keyPath, isEqualTo: value))
self.init(value == nil || value is NSNull
? Where("\(keyPath) == nil")
: Where("\(keyPath) == %@", value!))
}
/**
@@ -99,7 +101,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
@objc
public convenience init(keyPath: KeyPath, isMemberOf list: [CoreDataNativeType]) {
self.init(Where(keyPath, isMemberOf: list))
self.init(Where("\(keyPath) IN %@", list as NSArray))
}
/**