diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index 08beafb..856048e 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -80,10 +80,10 @@ B50392FA1C47963F009900CA /* NSManagedObject+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50392F81C478FF3009900CA /* NSManagedObject+Transaction.swift */; }; B50392FB1C479640009900CA /* NSManagedObject+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50392F81C478FF3009900CA /* NSManagedObject+Transaction.swift */; }; B504D0D61B02362500B2BBB1 /* CoreStore+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B504D0D51B02362500B2BBB1 /* CoreStore+Setup.swift */; }; - B509C7F41E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift */; }; - B509C7F51E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift */; }; - B509C7F61E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift */; }; - B509C7F71E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift */; }; + B509C7F41E54511B0061C547 /* CoreStoreImportableAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreImportableAttributeType.swift */; }; + B509C7F51E54511B0061C547 /* CoreStoreImportableAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreImportableAttributeType.swift */; }; + B509C7F61E54511B0061C547 /* CoreStoreImportableAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreImportableAttributeType.swift */; }; + B509C7F71E54511B0061C547 /* CoreStoreImportableAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B509C7F31E54511B0061C547 /* CoreStoreImportableAttributeType.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 */; }; @@ -263,10 +263,10 @@ B5489F501CF603D5008B4978 /* FromTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5489F4F1CF603D5008B4978 /* FromTests.swift */; }; B5489F511CF603D5008B4978 /* FromTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5489F4F1CF603D5008B4978 /* FromTests.swift */; }; B5489F521CF603D5008B4978 /* FromTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5489F4F1CF603D5008B4978 /* FromTests.swift */; }; - B549F65E1E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F65D1E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift */; }; - B549F65F1E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F65D1E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift */; }; - B549F6601E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F65D1E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift */; }; - B549F6611E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F65D1E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift */; }; + B549F65E1E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F65D1E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift */; }; + B549F65F1E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F65D1E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift */; }; + B549F6601E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F65D1E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift */; }; + B549F6611E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F65D1E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift */; }; B549F6731E56A92800FBAB2D /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */; }; B549F6741E56A92800FBAB2D /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */; }; B549F6751E56A92800FBAB2D /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */; }; @@ -612,7 +612,7 @@ B501FDE61CA8D20500BE22EF /* CSListObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSListObserver.swift; sourceTree = ""; }; B50392F81C478FF3009900CA /* NSManagedObject+Transaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+Transaction.swift"; sourceTree = ""; }; B504D0D51B02362500B2BBB1 /* CoreStore+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+Setup.swift"; sourceTree = ""; }; - B509C7F31E54511B0061C547 /* CoreStoreUniqueIDAttributeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreUniqueIDAttributeType.swift; sourceTree = ""; }; + B509C7F31E54511B0061C547 /* CoreStoreImportableAttributeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreImportableAttributeType.swift; sourceTree = ""; }; B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectModel+Setup.swift"; sourceTree = ""; }; B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+CustomDebugStringConvertible.swift"; sourceTree = ""; }; B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFetchedResultsController+Convenience.swift"; sourceTree = ""; }; @@ -649,7 +649,7 @@ B5489F451CF5F017008B4978 /* TransactionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionTests.swift; sourceTree = ""; }; B5489F4B1CF5F743008B4978 /* BaseTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseTestCase.swift; sourceTree = ""; }; B5489F4F1CF603D5008B4978 /* FromTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FromTests.swift; sourceTree = ""; }; - B549F65D1E569C7400FBAB2D /* CoreStoreQueryingAttributeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreQueryingAttributeType.swift; sourceTree = ""; }; + B549F65D1E569C7400FBAB2D /* CoreStoreQueryableAttributeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreQueryableAttributeType.swift; sourceTree = ""; }; B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataNativeType.swift; sourceTree = ""; }; B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedResultsControllerDelegate.swift; sourceTree = ""; }; B5519A3F1CA1B17B002BEF78 /* ErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTests.swift; sourceTree = ""; }; diff --git a/CoreStoreTests/FetchTests.swift b/CoreStoreTests/FetchTests.swift index 7963785..c86f60b 100644 --- a/CoreStoreTests/FetchTests.swift +++ b/CoreStoreTests/FetchTests.swift @@ -868,6 +868,24 @@ final class FetchTests: BaseTestDataTestCase { } XCTAssertNil(objects) + let objectIDs = self.expectLogger([.logWarning]) { + + stack.fetchObjectIDs(from, fetchClauses) + } + XCTAssertNil(objectIDs) + } + do { + + let fetchClauses: [FetchClause] = [ + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + ] + let objects = self.expectLogger([.logWarning]) { + + stack.fetchAll(from, fetchClauses) + } + XCTAssertNil(objects) + let objectIDs = self.expectLogger([.logWarning]) { stack.fetchObjectIDs(from, fetchClauses) @@ -1445,6 +1463,18 @@ final class FetchTests: BaseTestDataTestCase { } XCTAssertNil(count) } + do { + + let count = self.expectLogger([.logWarning]) { + + stack.fetchCount( + from, + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + ) + } + XCTAssertNil(count) + } } } } @@ -1592,6 +1622,18 @@ final class FetchTests: BaseTestDataTestCase { } XCTAssertNil(count) } + do { + + let count = self.expectLogger([.logWarning]) { + + stack.fetchCount( + from, + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + ) + } + XCTAssertNil(count) + } } } } @@ -2361,6 +2403,24 @@ final class FetchTests: BaseTestDataTestCase { } XCTAssertNil(objects) + let objectIDs = self.expectLogger([.logWarning]) { + + transaction.fetchObjectIDs(from, fetchClauses) + } + XCTAssertNil(objectIDs) + } + do { + + let fetchClauses: [FetchClause] = [ + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + ] + let objects = self.expectLogger([.logWarning]) { + + transaction.fetchAll(from, fetchClauses) + } + XCTAssertNil(objects) + let objectIDs = self.expectLogger([.logWarning]) { transaction.fetchObjectIDs(from, fetchClauses) @@ -2938,6 +2998,18 @@ final class FetchTests: BaseTestDataTestCase { } XCTAssertNil(count) } + do { + + let count = self.expectLogger([.logWarning]) { + + transaction.fetchCount( + from, + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + ) + } + XCTAssertNil(count) + } } } } @@ -3085,6 +3157,18 @@ final class FetchTests: BaseTestDataTestCase { } XCTAssertNil(count) } + do { + + let count = self.expectLogger([.logWarning]) { + + transaction.fetchCount( + from, + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + ) + } + XCTAssertNil(count) + } } } } diff --git a/CoreStoreTests/ImportTests.swift b/CoreStoreTests/ImportTests.swift index bfb6546..035a4c4 100644 --- a/CoreStoreTests/ImportTests.swift +++ b/CoreStoreTests/ImportTests.swift @@ -36,40 +36,40 @@ class ImportTests: BaseTestDataTestCase { @objc dynamic func test_ThatAttributeProtocols_BehaveCorrectly() { - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSNumber(value: true))?.boolValue, true) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSNumber(value: Int16.max))?.int16Value, Int16.max) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSNumber(value: Int32.max))?.int32Value, Int32.max) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSNumber(value: Int64.max))?.int64Value, Int64.max) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSNumber(value: MAXFLOAT))?.floatValue, MAXFLOAT) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSNumber(value: Double(MAXFLOAT)))?.doubleValue, Double(MAXFLOAT)) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: true))?.boolValue, true) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int16.max))?.int16Value, Int16.max) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int32.max))?.int32Value, Int32.max) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Int64.max))?.int64Value, Int64.max) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: MAXFLOAT))?.floatValue, MAXFLOAT) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSNumber(value: Double(MAXFLOAT)))?.doubleValue, Double(MAXFLOAT)) - XCTAssertEqual(NSDecimalNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: "1"))?.boolValue, true) - XCTAssertEqual(NSDecimalNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max) - XCTAssertEqual(NSDecimalNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max) - XCTAssertEqual(NSDecimalNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max) - XCTAssertEqual(NSDecimalNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue) - XCTAssertEqual(NSDecimalNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue) + XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true) + XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max) + XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max) + XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max) + XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue) + XCTAssertEqual(NSDecimalNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: "1"))?.boolValue, true) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue) - XCTAssertEqual(NSNumber.cs_fromUniqueIDNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: "1"))?.boolValue, true) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int16.max.description))?.int16Value, Int16.max) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int32.max.description))?.int32Value, Int32.max) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: Int64.max.description))?.int64Value, Int64.max) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.doubleValue, NSDecimalNumber(string: MAXFLOAT.description).doubleValue) + XCTAssertEqual(NSNumber.cs_fromImportableNativeType(NSDecimalNumber(string: MAXFLOAT.description))?.floatValue, NSDecimalNumber(string: MAXFLOAT.description).floatValue) - XCTAssertNil(NSDecimalNumber.cs_fromUniqueIDNativeType(NSNumber(value: true))) - XCTAssertNil(NSDecimalNumber.cs_fromUniqueIDNativeType(NSNumber(value: Int16.max))) - XCTAssertNil(NSDecimalNumber.cs_fromUniqueIDNativeType(NSNumber(value: Int32.max))) - XCTAssertNil(NSDecimalNumber.cs_fromUniqueIDNativeType(NSNumber(value: Int64.max))) - XCTAssertNil(NSDecimalNumber.cs_fromUniqueIDNativeType(NSNumber(value: MAXFLOAT))) - XCTAssertNil(NSDecimalNumber.cs_fromUniqueIDNativeType(NSNumber(value: Double(MAXFLOAT)))) + XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: true))) + XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int16.max))) + XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int32.max))) + XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Int64.max))) + XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: MAXFLOAT))) + XCTAssertNil(NSDecimalNumber.cs_fromImportableNativeType(NSNumber(value: Double(MAXFLOAT)))) - XCTAssertEqual(true.cs_toUniqueIDNativeType(), NSNumber(value: true)) - XCTAssertEqual(Int16.max.cs_toUniqueIDNativeType(), NSNumber(value: Int16.max)) - XCTAssertEqual(Int32.max.cs_toUniqueIDNativeType(), NSNumber(value: Int32.max)) - XCTAssertEqual(Int64.max.cs_toUniqueIDNativeType(), NSNumber(value: Int64.max)) - XCTAssertEqual(MAXFLOAT.cs_toUniqueIDNativeType(), NSNumber(value: MAXFLOAT)) - XCTAssertEqual(Double(MAXFLOAT).cs_toUniqueIDNativeType(), NSNumber(value: Double(MAXFLOAT))) + XCTAssertEqual(true.cs_toQueryableNativeType(), NSNumber(value: true)) + XCTAssertEqual(Int16.max.cs_toQueryableNativeType(), NSNumber(value: Int16.max)) + XCTAssertEqual(Int32.max.cs_toQueryableNativeType(), NSNumber(value: Int32.max)) + XCTAssertEqual(Int64.max.cs_toQueryableNativeType(), NSNumber(value: Int64.max)) + XCTAssertEqual(MAXFLOAT.cs_toQueryableNativeType(), NSNumber(value: MAXFLOAT)) + XCTAssertEqual(Double(MAXFLOAT).cs_toQueryableNativeType(), NSNumber(value: Double(MAXFLOAT))) } @objc diff --git a/Sources/Fetching and Querying/Concrete Clauses/Where.swift b/Sources/Fetching and Querying/Concrete Clauses/Where.swift index 60bbb50..52549dc 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/Where.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/Where.swift @@ -103,13 +103,24 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { self.init(NSPredicate(format: format, argumentArray: argumentArray)) } + /** + Initializes a `Where` clause that compares equality to `nil` + + - parameter keyPath: the keyPath to compare with + - parameter value: the arguments for the `==` operator + */ + public init(_ keyPath: KeyPath, isEqualTo value: Void?) { + + self.init(NSPredicate(format: "\(keyPath) == nil")) + } + /** Initializes a `Where` clause that compares equality - parameter keyPath: the keyPath to compare with - parameter value: the arguments for the `==` operator */ - public init(_ keyPath: KeyPath, isEqualTo value: T?) { + public init(_ keyPath: KeyPath, isEqualTo value: T?) { switch value { @@ -118,7 +129,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { self.init(NSPredicate(format: "\(keyPath) == nil")) case let value?: - self.init(NSPredicate(format: "\(keyPath) == %@", argumentArray: [value.cs_toQueryingNativeType()])) + self.init(NSPredicate(format: "\(keyPath) == %@", argumentArray: [value.cs_toQueryableNativeType()])) } } @@ -128,9 +139,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(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: CoreStoreQueryingAttributeType { + public init(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: CoreStoreQueryableAttributeType { - self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryingNativeType() }) as NSArray)) + self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_toQueryableNativeType() }) as NSArray)) } /** diff --git a/Sources/Fetching and Querying/CoreStoreQueryableAttributeType.swift b/Sources/Fetching and Querying/CoreStoreQueryableAttributeType.swift new file mode 100644 index 0000000..b0a63dd --- /dev/null +++ b/Sources/Fetching and Querying/CoreStoreQueryableAttributeType.swift @@ -0,0 +1,272 @@ +// +// CoreStoreQueryableAttributeType.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: - CoreStoreQueryableAttributeType + +public protocol CoreStoreQueryableAttributeType: Hashable { + + associatedtype QueryableNativeType: CoreDataNativeType + + func cs_toQueryableNativeType() -> QueryableNativeType +} + + +// MARK: - NSManagedObject + +extension NSManagedObject: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSManagedObjectID + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self.objectID + } +} + + +// MARK: - NSManagedObjectID + +extension NSManagedObjectID: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSManagedObjectID + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self + } +} + + +// MARK: - NSNumber + +extension NSNumber: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self + } +} + + +// MARK: - NSString + +extension NSString: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSString + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self + } +} + + +// MARK: - NSDate + +extension NSDate: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSDate + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self + } +} + + +// MARK: - NSData + +extension NSData: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSData + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self + } +} + + +// MARK: - Bool + +extension Bool: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSNumber + } +} + + +// MARK: - Int16 + +extension Int16: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSNumber + } +} + + +// MARK: - Int32 + +extension Int32: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSNumber + } +} + + +// MARK: - Int64 + +extension Int64: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSNumber + } +} + + +// MARK: - Int + +extension Int: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSNumber + } +} + + +// MARK: - Double + +extension Double: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSNumber + } +} + + +// MARK: - Float + +extension Float: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSNumber + } +} + + +// MARK: - CGFloat + +extension CGFloat: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNumber + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSNumber + } +} + + +// MARK: - Date + +extension Date: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSDate + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSDate + } +} + + +// MARK: - String + +extension String: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSString + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSString + } +} + + +// MARK: - Data + +extension Data: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSData + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self as NSData + } +} + + +// MARK: - NSNull + +extension NSNull: CoreStoreQueryableAttributeType { + + public typealias QueryableNativeType = NSNull + + public func cs_toQueryableNativeType() -> QueryableNativeType { + + return self + } +} diff --git a/Sources/Fetching and Querying/CoreStoreQueryingAttributeType.swift b/Sources/Fetching and Querying/CoreStoreQueryingAttributeType.swift deleted file mode 100644 index ddb4028..0000000 --- a/Sources/Fetching and Querying/CoreStoreQueryingAttributeType.swift +++ /dev/null @@ -1,272 +0,0 @@ -// -// 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 - } -} diff --git a/Sources/Importing/CoreStoreImportableAttributeType.swift b/Sources/Importing/CoreStoreImportableAttributeType.swift new file mode 100644 index 0000000..8e14e9c --- /dev/null +++ b/Sources/Importing/CoreStoreImportableAttributeType.swift @@ -0,0 +1,317 @@ +// +// CoreStoreImportableAttributeType.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: - CoreStoreImportableAttributeType + +public protocol CoreStoreImportableAttributeType: CoreStoreQueryableAttributeType { + + associatedtype ImportableNativeType: QueryableNativeType + + @inline(__always) + static func cs_emptyValue() -> Self + + @inline(__always) + static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? +} + + +// MARK: - NSNumber + +extension NSNumber: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSNumber + + @nonobjc @inline(__always) + public class func cs_emptyValue() -> Self { + + return self.init() + } + + @nonobjc @inline(__always) + public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? { + + func forceCast(_ value: Any) -> T? { + + return value as? T + } + return forceCast(value) + } +} + + +// MARK: - NSString + +extension NSString: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSString + + @nonobjc @inline(__always) + public class func cs_emptyValue() -> Self { + + return self.init() + } + + @nonobjc @inline(__always) + public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? { + + func forceCast(_ value: Any) -> T? { + + return value as? T + } + return forceCast(value) + } +} + + +// MARK: - NSDate + +extension NSDate: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSDate + + @nonobjc @inline(__always) + public class func cs_emptyValue() -> Self { + + return self.init(timeIntervalSinceReferenceDate: 0) + } + + @nonobjc @inline(__always) + public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? { + + func forceCast(_ value: Any) -> T? { + + return value as? T + } + return forceCast(value) + } +} + + +// MARK: - NSData + +extension NSData: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSData + + @nonobjc @inline(__always) + public class func cs_emptyValue() -> Self { + + return self.init() + } + + @nonobjc @inline(__always) + public class func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Self? { + + func forceCast(_ value: Any) -> T? { + + return value as? T + } + return forceCast(value) + } +} + + +// MARK: - Bool + +extension Bool: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSNumber + + @inline(__always) + public static func cs_emptyValue() -> Bool { + + return false + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Bool? { + + return value.boolValue + } +} + + +// MARK: - Int16 + +extension Int16: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSNumber + + @inline(__always) + public static func cs_emptyValue() -> Int16 { + + return 0 + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int16? { + + return value.int16Value + } +} + + +// MARK: - Int32 + +extension Int32: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSNumber + + @inline(__always) + public static func cs_emptyValue() -> Int32 { + + return 0 + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int32? { + + return value.int32Value + } +} + + +// MARK: - Int64 + +extension Int64: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSNumber + + @inline(__always) + public static func cs_emptyValue() -> Int64 { + + return 0 + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Int64? { + + return value.int64Value + } +} + + +// MARK: - Double + +extension Double: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSNumber + + @inline(__always) + public static func cs_emptyValue() -> Double { + + return 0 + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Double? { + + return value.doubleValue + } +} + + +// MARK: - Float + +extension Float: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSNumber + + @inline(__always) + public static func cs_emptyValue() -> Float { + + return 0 + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Float? { + + return value.floatValue + } +} + + +// MARK: - Date + +extension Date: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSDate + + @inline(__always) + public static func cs_emptyValue() -> Date { + + return Date(timeIntervalSinceReferenceDate: 0) + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Date? { + + return value as Date + } +} + + +// MARK: - String + +extension String: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSString + + @inline(__always) + public static func cs_emptyValue() -> String { + + return "" + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> String? { + + return value as String + } +} + + +// MARK: - Data + +extension Data: CoreStoreImportableAttributeType { + + public typealias ImportableNativeType = NSData + + @inline(__always) + public static func cs_emptyValue() -> Data { + + return Data() + } + + @inline(__always) + public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Data? { + + return value as Data + } +} diff --git a/Sources/Importing/CoreStoreUniqueIDAttributeType.swift b/Sources/Importing/CoreStoreUniqueIDAttributeType.swift deleted file mode 100644 index c2d112b..0000000 --- a/Sources/Importing/CoreStoreUniqueIDAttributeType.swift +++ /dev/null @@ -1,288 +0,0 @@ -// -// 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(_ 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(_ 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(_ 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(_ 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 - } -} diff --git a/Sources/Importing/ImportableUniqueObject.swift b/Sources/Importing/ImportableUniqueObject.swift index d5a4061..db7e1dc 100644 --- a/Sources/Importing/ImportableUniqueObject.swift +++ b/Sources/Importing/ImportableUniqueObject.swift @@ -59,7 +59,7 @@ public protocol ImportableUniqueObject: ImportableObject { /** The data type for the entity's unique ID attribute */ - associatedtype UniqueIDType: CoreStoreUniqueIDAttributeType + associatedtype UniqueIDType: CoreStoreImportableAttributeType /** The keyPath to the entity's unique ID attribute @@ -192,14 +192,14 @@ public extension ImportableUniqueObject where Self: NSManagedObject { get { - return UniqueIDType.cs_fromUniqueIDNativeType( - self.value(forKey: type(of: self).uniqueIDKeyPath) as! UniqueIDType.NativeTypeForUniqueID + return UniqueIDType.cs_fromImportableNativeType( + self.value(forKey: type(of: self).uniqueIDKeyPath) as! UniqueIDType.ImportableNativeType )! } set { self.setValue( - newValue.cs_toUniqueIDNativeType(), + newValue.cs_toQueryableNativeType(), forKey: type(of: self).uniqueIDKeyPath ) }