mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-15 05:33:31 +01:00
Where clauses are now more strict with the argument types
This commit is contained in:
@@ -84,6 +84,10 @@
|
||||
B50956B91E30B810003DF913 /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50956B71E30B810003DF913 /* CoreDataNativeType.swift */; };
|
||||
B50956BA1E30B810003DF913 /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50956B71E30B810003DF913 /* CoreDataNativeType.swift */; };
|
||||
B50956BB1E30B810003DF913 /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50956B71E30B810003DF913 /* CoreDataNativeType.swift */; };
|
||||
B509C7F41E54511B0061C547 /* CoreStoreSupportedAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreSupportedAttributeType.swift */; };
|
||||
B509C7F51E54511B0061C547 /* CoreStoreSupportedAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreSupportedAttributeType.swift */; };
|
||||
B509C7F61E54511B0061C547 /* CoreStoreSupportedAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreSupportedAttributeType.swift */; };
|
||||
B509C7F71E54511B0061C547 /* CoreStoreSupportedAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreSupportedAttributeType.swift */; };
|
||||
B51BE06A1B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */; };
|
||||
B51FE5AB1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; };
|
||||
B51FE5AD1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; };
|
||||
@@ -605,6 +609,7 @@
|
||||
B50392F81C478FF3009900CA /* NSManagedObject+Transaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+Transaction.swift"; sourceTree = "<group>"; };
|
||||
B504D0D51B02362500B2BBB1 /* CoreStore+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+Setup.swift"; sourceTree = "<group>"; };
|
||||
B50956B71E30B810003DF913 /* CoreDataNativeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataNativeType.swift; sourceTree = "<group>"; };
|
||||
B509C7F31E54511B0061C547 /* CoreStoreSupportedAttributeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreSupportedAttributeType.swift; sourceTree = "<group>"; };
|
||||
B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectModel+Setup.swift"; sourceTree = "<group>"; };
|
||||
B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+CustomDebugStringConvertible.swift"; sourceTree = "<group>"; };
|
||||
B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFetchedResultsController+Convenience.swift"; sourceTree = "<group>"; };
|
||||
@@ -1104,6 +1109,7 @@
|
||||
B5F1DA8F1B9AA991007C5CBB /* ImportableUniqueObject.swift */,
|
||||
B5E834B81B76311F001D3D50 /* BaseDataTransaction+Importing.swift */,
|
||||
B50956B71E30B810003DF913 /* CoreDataNativeType.swift */,
|
||||
B509C7F31E54511B0061C547 /* CoreStoreSupportedAttributeType.swift */,
|
||||
);
|
||||
path = Importing;
|
||||
sourceTree = "<group>";
|
||||
@@ -1580,6 +1586,7 @@
|
||||
B56007161B4018AB00A9A8F9 /* MigrationChain.swift in Sources */,
|
||||
B5E1B59D1CAA2568007FD580 /* CSDataStack+Observing.swift in Sources */,
|
||||
B5ECDC231CA81A3900C7F112 /* CSCoreStore+Querying.swift in Sources */,
|
||||
B509C7F41E54511B0061C547 /* CoreStoreSupportedAttributeType.swift in Sources */,
|
||||
B5E84F0E1AFF847B0064E85B /* Tweak.swift in Sources */,
|
||||
B5E1B5931CAA0C15007FD580 /* CSObjectMonitor.swift in Sources */,
|
||||
B5ECDC291CA81CC700C7F112 /* CSDataStack+Transaction.swift in Sources */,
|
||||
@@ -1734,6 +1741,7 @@
|
||||
B5D3F6461C887C0A00C7492A /* LegacySQLiteStore.swift in Sources */,
|
||||
B5E1B59F1CAA2568007FD580 /* CSDataStack+Observing.swift in Sources */,
|
||||
B5ECDC251CA81A3900C7F112 /* CSCoreStore+Querying.swift in Sources */,
|
||||
B509C7F51E54511B0061C547 /* CoreStoreSupportedAttributeType.swift in Sources */,
|
||||
82BA18B31C4BBD3900A0916E /* ImportableUniqueObject.swift in Sources */,
|
||||
B5E1B5951CAA0C15007FD580 /* CSObjectMonitor.swift in Sources */,
|
||||
B5ECDC2B1CA81CC700C7F112 /* CSDataStack+Transaction.swift in Sources */,
|
||||
@@ -1888,6 +1896,7 @@
|
||||
B5220E241D13085E009BC71E /* NSFetchedResultsController+Convenience.swift in Sources */,
|
||||
B559CD471CAA8B6300E4D58B /* CSSetupResult.swift in Sources */,
|
||||
B5ECDBF01CA6BF2000C7F112 /* CSFrom.swift in Sources */,
|
||||
B509C7F71E54511B0061C547 /* CoreStoreSupportedAttributeType.swift in Sources */,
|
||||
B5220E1F1D130810009BC71E /* CSListObserver.swift in Sources */,
|
||||
B52DD1941BE1F92500949AFE /* CoreStore.swift in Sources */,
|
||||
B52DD1A61BE1F92F00949AFE /* BaseDataTransaction+Importing.swift in Sources */,
|
||||
@@ -2042,6 +2051,7 @@
|
||||
B5E1B5A01CAA2568007FD580 /* CSDataStack+Observing.swift in Sources */,
|
||||
B5ECDC261CA81A3900C7F112 /* CSCoreStore+Querying.swift in Sources */,
|
||||
B563217F1BD65216006C9394 /* CoreStore.swift in Sources */,
|
||||
B509C7F61E54511B0061C547 /* CoreStoreSupportedAttributeType.swift in Sources */,
|
||||
B5E1B5961CAA0C15007FD580 /* CSObjectMonitor.swift in Sources */,
|
||||
B5ECDC2C1CA81CC700C7F112 /* CSDataStack+Transaction.swift in Sources */,
|
||||
B56321911BD65216006C9394 /* BaseDataTransaction+Importing.swift in Sources */,
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -29,288 +29,44 @@ import CoreData
|
||||
|
||||
// MARK: - CoreDataNativeType
|
||||
|
||||
public protocol CoreDataNativeType: class, NSObjectProtocol, AnyObject {}
|
||||
@objc public protocol CoreDataNativeType: class, NSObjectProtocol, AnyObject {}
|
||||
|
||||
|
||||
// MARK: - NSNumber
|
||||
|
||||
extension NSNumber: CoreDataNativeType {}
|
||||
|
||||
|
||||
// MARK: - NSString
|
||||
|
||||
extension NSString: CoreDataNativeType {}
|
||||
|
||||
|
||||
// MARK: - NSDate
|
||||
|
||||
extension NSDate: CoreDataNativeType {}
|
||||
|
||||
|
||||
// MARK: - NSData
|
||||
|
||||
extension NSData: CoreDataNativeType {}
|
||||
|
||||
|
||||
// MARK: - NSSet
|
||||
|
||||
extension NSSet: CoreDataNativeType {}
|
||||
|
||||
|
||||
// MARK: - NSOrderedSet
|
||||
|
||||
extension NSOrderedSet: CoreDataNativeType {}
|
||||
|
||||
|
||||
public protocol CoreStoreSupportedAttributeType {
|
||||
|
||||
associatedtype CoreStoreNativeType: CoreDataNativeType
|
||||
|
||||
static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Self?
|
||||
func cs_toNativeType() -> CoreStoreNativeType
|
||||
}
|
||||
// MARK: - NSManagedObject
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
extension NSManagedObject: CoreDataNativeType {}
|
||||
|
||||
|
||||
// MARK: - NSManagedObjectID
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension NSManagedObjectID: CoreDataNativeType {}
|
||||
|
||||
372
Sources/Importing/CoreStoreSupportedAttributeType.swift
Normal file
372
Sources/Importing/CoreStoreSupportedAttributeType.swift
Normal file
@@ -0,0 +1,372 @@
|
||||
//
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
||||
- parameter value: the arguments for the `==` operator
|
||||
*/
|
||||
@objc
|
||||
public convenience init(keyPath: KeyPath, isEqualTo value: NSObject?) {
|
||||
public convenience init(keyPath: KeyPath, isEqualTo value: CoreDataNativeType?) {
|
||||
|
||||
self.init(Where(keyPath, isEqualTo: value))
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
||||
- parameter list: the array to check membership of
|
||||
*/
|
||||
@objc
|
||||
public convenience init(keyPath: KeyPath, isMemberOf list: [NSObject]) {
|
||||
public convenience init(keyPath: KeyPath, isMemberOf list: [CoreDataNativeType]) {
|
||||
|
||||
self.init(Where(keyPath, isMemberOf: list))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user