diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index c5a6d7e..cd4304e 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -324,10 +324,10 @@ B5519A601CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; }; B5519A611CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; }; B5519A621CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; }; - B55514EA1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; }; - B55514EB1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; }; - B55514EC1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; }; - B55514ED1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; }; + B55514EA1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */; }; + B55514EB1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */; }; + B55514EC1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */; }; + B55514ED1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */; }; B55717441D15B09E009BDBCA /* CoreStoreBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */; settings = {ATTRIBUTES = (Public, ); }; }; B55717451D15B09F009BDBCA /* CoreStoreBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */; settings = {ATTRIBUTES = (Public, ); }; }; B55717461D15B0A1009BDBCA /* CoreStoreBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -477,6 +477,10 @@ B59FA0B01CCBACA7007C9BCA /* ICloudStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59FA0AD1CCBAC95007C9BCA /* ICloudStore.swift */; }; B59FA0B11CCBACA7007C9BCA /* ICloudStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59FA0AD1CCBAC95007C9BCA /* ICloudStore.swift */; }; B59FA0B21CCBACA8007C9BCA /* ICloudStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59FA0AD1CCBAC95007C9BCA /* ICloudStore.swift */; }; + B5A1DAC81F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1DAC71F111BFA003CF369 /* Where+NSManagedObject.swift */; }; + B5A1DAC91F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1DAC71F111BFA003CF369 /* Where+NSManagedObject.swift */; }; + B5A1DACA1F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1DAC71F111BFA003CF369 /* Where+NSManagedObject.swift */; }; + B5A1DACB1F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1DAC71F111BFA003CF369 /* Where+NSManagedObject.swift */; }; B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A261201B64BFDB006EB6D3 /* MigrationType.swift */; }; B5A5F2661CAEC50F004AB9AF /* CSSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A5F2651CAEC50F004AB9AF /* CSSelect.swift */; }; B5A5F2681CAEC50F004AB9AF /* CSSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A5F2651CAEC50F004AB9AF /* CSSelect.swift */; }; @@ -790,7 +794,7 @@ B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSAsynchronousDataTransaction.swift; sourceTree = ""; }; B5548CD51BD65AE00077652A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; B5548CD71BD65AE50077652A /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; }; - B55514E91EED8BF900BAB888 /* FetchCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchCondition.swift; sourceTree = ""; }; + B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChainedClauseBuilder.swift; sourceTree = ""; }; B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreStoreBridge.h; sourceTree = ""; }; B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSetupResult.swift; sourceTree = ""; }; B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSStorageInterface.swift; sourceTree = ""; }; @@ -827,6 +831,7 @@ B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryableSource.swift; sourceTree = ""; }; B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSPersistentStoreCoordinator+Setup.swift"; sourceTree = ""; }; B59FA0AD1CCBAC95007C9BCA /* ICloudStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ICloudStore.swift; sourceTree = ""; }; + B5A1DAC71F111BFA003CF369 /* Where+NSManagedObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Where+NSManagedObject.swift"; sourceTree = ""; }; B5A261201B64BFDB006EB6D3 /* MigrationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationType.swift; sourceTree = ""; }; B5A5F2651CAEC50F004AB9AF /* CSSelect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSelect.swift; sourceTree = ""; }; B5A991EB1E9DC2CE0091A2E3 /* VersionLock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionLock.swift; sourceTree = ""; }; @@ -1251,6 +1256,15 @@ name = "Dynamic Models"; sourceTree = ""; }; + B5A1DAC61F111BBE003CF369 /* KeyPath Utilities */ = { + isa = PBXGroup; + children = ( + B5A1DAC71F111BFA003CF369 /* Where+NSManagedObject.swift */, + B5D339EB1E9495E500C880DE /* CoreStoreObject+Querying.swift */, + ); + name = "KeyPath Utilities"; + sourceTree = ""; + }; B5A5F26B1CAFF8D0004AB9AF /* Swift */ = { isa = PBXGroup; children = ( @@ -1374,14 +1388,14 @@ B5E84EFD1AFF847B0064E85B /* Fetching and Querying */ = { isa = PBXGroup; children = ( - B5D339EB1E9495E500C880DE /* CoreStoreObject+Querying.swift */, B5E84EFE1AFF847B0064E85B /* BaseDataTransaction+Querying.swift */, B5E84F061AFF847B0064E85B /* DataStack+Querying.swift */, B5E84F071AFF847B0064E85B /* CoreStore+Querying.swift */, B596BBB51DD5BC67001DCDD9 /* FetchableSource.swift */, - B55514E91EED8BF900BAB888 /* FetchCondition.swift */, + B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */, B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */, B549F65D1E569C7400FBAB2D /* QueryableAttributeType.swift */, + B5A1DAC61F111BBE003CF369 /* KeyPath Utilities */, B5E84F0A1AFF847B0064E85B /* Protocol Clauses */, B5E84EFF1AFF847B0064E85B /* Concrete Clauses */, ); @@ -1800,7 +1814,7 @@ B5D339D81E9489AB00C880DE /* CoreStoreObject.swift in Sources */, B5D3F6451C887C0A00C7492A /* LegacySQLiteStore.swift in Sources */, B56923FA1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, - B55514EA1EED8BF900BAB888 /* FetchCondition.swift in Sources */, + B55514EA1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */, B596BBBB1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, B5ECDBFF1CA80CBA00C7F112 /* CSWhere.swift in Sources */, B5ECDC051CA8138100C7F112 /* CSOrderBy.swift in Sources */, @@ -1860,6 +1874,7 @@ B501FDE71CA8D20500BE22EF /* CSListObserver.swift in Sources */, B5E41EC01EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B501FDE21CA8D1F500BE22EF /* CSListMonitor.swift in Sources */, + B5A1DAC81F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */, 2F291E2719C6D3CF007AF63F /* CoreStore.swift in Sources */, B5ECDC111CA816E500C7F112 /* CSTweak.swift in Sources */, B56923C41EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, @@ -1987,7 +2002,7 @@ B5D339D91E9489AB00C880DE /* CoreStoreObject.swift in Sources */, 82BA18CE1C4BBD7100A0916E /* FetchedResultsControllerDelegate.swift in Sources */, B56923FB1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, - B55514EB1EED8BF900BAB888 /* FetchCondition.swift in Sources */, + B55514EB1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */, B596BBBC1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, B5ECDC011CA80CBA00C7F112 /* CSWhere.swift in Sources */, B5ECDC071CA8138100C7F112 /* CSOrderBy.swift in Sources */, @@ -2047,6 +2062,7 @@ B501FDE91CA8D20500BE22EF /* CSListObserver.swift in Sources */, B5E41EC11EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B501FDE41CA8D1F500BE22EF /* CSListMonitor.swift in Sources */, + B5A1DAC91F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */, B5FE4DA31C8481E100FA6A91 /* StorageInterface.swift in Sources */, B5ECDC131CA816E500C7F112 /* CSTweak.swift in Sources */, B56923C51EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, @@ -2174,7 +2190,7 @@ B5D339DB1E9489AB00C880DE /* CoreStoreObject.swift in Sources */, B52DD1951BE1F92500949AFE /* CoreStoreError.swift in Sources */, B56923FD1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, - B55514ED1EED8BF900BAB888 /* FetchCondition.swift in Sources */, + B55514ED1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */, B596BBBE1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, B546F9601C9A12B800D5AC55 /* CSSQliteStore.swift in Sources */, B5ECDC0F1CA8161B00C7F112 /* CSGroupBy.swift in Sources */, @@ -2234,6 +2250,7 @@ B559CD4D1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B5E41EC31EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B5ECDBE91CA6BEA300C7F112 /* CSClauseTypes.swift in Sources */, + B5A1DACB1F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */, B52DD1B81BE1F94000949AFE /* DataStack+Migration.swift in Sources */, B5ECDC091CA8138100C7F112 /* CSOrderBy.swift in Sources */, B56923C71EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, @@ -2361,7 +2378,7 @@ B5D339DA1E9489AB00C880DE /* CoreStoreObject.swift in Sources */, B5ECDC021CA80CBA00C7F112 /* CSWhere.swift in Sources */, B56923FC1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, - B55514EC1EED8BF900BAB888 /* FetchCondition.swift in Sources */, + B55514EC1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */, B596BBBD1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, B5ECDC081CA8138100C7F112 /* CSOrderBy.swift in Sources */, B5E1B59B1CAA0C23007FD580 /* CSObjectObserver.swift in Sources */, @@ -2421,6 +2438,7 @@ B501FDE51CA8D1F500BE22EF /* CSListMonitor.swift in Sources */, B5E41EC21EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B5ECDC141CA816E500C7F112 /* CSTweak.swift in Sources */, + B5A1DACA1F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */, B56321AE1BD6521C006C9394 /* NotificationObserver.swift in Sources */, B56321931BD65216006C9394 /* DataStack+Querying.swift in Sources */, B56923C61EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, diff --git a/CoreStoreTests/ConvenienceTests.swift b/CoreStoreTests/ConvenienceTests.swift index 807d943..98b24cf 100644 --- a/CoreStoreTests/ConvenienceTests.swift +++ b/CoreStoreTests/ConvenienceTests.swift @@ -40,8 +40,8 @@ class ConvenienceTests: BaseTestCase { let controller = stack.createFetchedResultsController( From(), SectionBy(#keyPath(TestEntity1.testString)), - Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100), - OrderBy(.ascending(#keyPath(TestEntity1.testString))), + Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100), + OrderBy(.ascending(#keyPath(TestEntity1.testString))), Tweak { $0.fetchLimit = 10 } ) XCTAssertEqual(controller.managedObjectContext, stack.mainContext) @@ -49,11 +49,11 @@ class ConvenienceTests: BaseTestCase { XCTAssertEqual(controller.sectionNameKeyPath, #keyPath(TestEntity1.testString)) XCTAssertEqual( controller.fetchRequest.sortDescriptors!, - OrderBy(.ascending(#keyPath(TestEntity1.testString))).sortDescriptors + OrderBy(.ascending(#keyPath(TestEntity1.testString))).sortDescriptors ) XCTAssertEqual( controller.fetchRequest.predicate, - Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100).predicate + Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100).predicate ) XCTAssertEqual(controller.fetchRequest.fetchLimit, 10) } @@ -69,8 +69,8 @@ class ConvenienceTests: BaseTestCase { let controller = transaction.createFetchedResultsController( From(), SectionBy(#keyPath(TestEntity1.testString)), - Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100), - OrderBy(.ascending(#keyPath(TestEntity1.testString))), + Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100), + OrderBy(.ascending(#keyPath(TestEntity1.testString))), Tweak { $0.fetchLimit = 10 } ) XCTAssertEqual(controller.managedObjectContext, transaction.context) @@ -78,11 +78,11 @@ class ConvenienceTests: BaseTestCase { XCTAssertEqual(controller.sectionNameKeyPath, #keyPath(TestEntity1.testString)) XCTAssertEqual( controller.fetchRequest.sortDescriptors!, - OrderBy(.ascending(#keyPath(TestEntity1.testString))).sortDescriptors + OrderBy(.ascending(#keyPath(TestEntity1.testString))).sortDescriptors ) XCTAssertEqual( controller.fetchRequest.predicate, - Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100).predicate + Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100).predicate ) XCTAssertEqual(controller.fetchRequest.fetchLimit, 10) } diff --git a/CoreStoreTests/FetchTests.swift b/CoreStoreTests/FetchTests.swift index a700184..5d1037e 100644 --- a/CoreStoreTests/FetchTests.swift +++ b/CoreStoreTests/FetchTests.swift @@ -43,7 +43,7 @@ final class FetchTests: BaseTestDataTestCase { let from = From() let fetchClauses: [FetchClause] = [ - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses)! do { @@ -146,7 +146,7 @@ final class FetchTests: BaseTestDataTestCase { let from = From() let fetchClauses: [FetchClause] = [ - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses)! do { @@ -285,8 +285,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -299,8 +299,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -313,8 +313,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -329,8 +329,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -343,8 +343,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -357,8 +357,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -373,8 +373,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = self.expectLogger([.logWarning]) { @@ -391,8 +391,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = self.expectLogger([.logWarning]) { @@ -424,8 +424,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -438,8 +438,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -452,8 +452,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -468,8 +468,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -482,8 +482,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -496,8 +496,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -512,8 +512,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -526,8 +526,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -540,8 +540,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -556,8 +556,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = self.expectLogger([.logWarning]) { @@ -574,8 +574,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = self.expectLogger([.logWarning]) { @@ -607,8 +607,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -621,8 +621,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -635,8 +635,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -651,8 +651,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -665,8 +665,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -679,8 +679,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -695,8 +695,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -709,8 +709,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -723,8 +723,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = stack.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -750,8 +750,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -776,8 +776,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -802,8 +802,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -820,8 +820,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -846,8 +846,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -872,8 +872,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -890,8 +890,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -908,8 +908,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -926,8 +926,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -959,8 +959,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -976,8 +976,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -993,8 +993,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -1011,8 +1011,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1036,8 +1036,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1061,8 +1061,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -1079,8 +1079,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1104,8 +1104,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1129,8 +1129,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -1147,7 +1147,7 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -1164,7 +1164,7 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -1196,8 +1196,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1213,8 +1213,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1230,8 +1230,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -1248,8 +1248,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1273,8 +1273,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1298,8 +1298,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -1316,8 +1316,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1341,8 +1341,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = stack.fetchAll(from, fetchClauses) @@ -1366,8 +1366,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = stack.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -1396,8 +1396,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1407,8 +1407,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1418,8 +1418,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -1432,8 +1432,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1443,8 +1443,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1454,8 +1454,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -1470,8 +1470,8 @@ final class FetchTests: BaseTestDataTestCase { stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -1482,8 +1482,8 @@ final class FetchTests: BaseTestDataTestCase { stack.fetchCount( from, - Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -1494,8 +1494,8 @@ final class FetchTests: BaseTestDataTestCase { stack.fetchCount( from, - Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -1519,8 +1519,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1530,8 +1530,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1541,8 +1541,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -1555,8 +1555,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1566,8 +1566,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1577,8 +1577,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -1591,8 +1591,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1602,8 +1602,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1613,8 +1613,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -1629,8 +1629,8 @@ final class FetchTests: BaseTestDataTestCase { stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -1641,8 +1641,8 @@ final class FetchTests: BaseTestDataTestCase { stack.fetchCount( from, - Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -1653,8 +1653,8 @@ final class FetchTests: BaseTestDataTestCase { stack.fetchCount( from, - Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -1678,8 +1678,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1689,8 +1689,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1700,8 +1700,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -1714,8 +1714,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1725,8 +1725,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1736,8 +1736,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -1750,8 +1750,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1761,8 +1761,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -1772,8 +1772,8 @@ final class FetchTests: BaseTestDataTestCase { let count = stack.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -1796,8 +1796,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -1810,8 +1810,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -1824,8 +1824,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -1843,8 +1843,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -1857,8 +1857,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -1871,8 +1871,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -1890,8 +1890,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = self.expectLogger([.logWarning]) { @@ -1908,8 +1908,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = self.expectLogger([.logWarning]) { @@ -1943,8 +1943,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -1957,8 +1957,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -1971,8 +1971,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -1990,8 +1990,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2004,8 +2004,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2018,8 +2018,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -2037,8 +2037,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2051,8 +2051,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2065,8 +2065,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -2084,8 +2084,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = self.expectLogger([.logWarning]) { @@ -2102,8 +2102,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = self.expectLogger([.logWarning]) { @@ -2137,8 +2137,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2151,8 +2151,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2165,8 +2165,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -2184,8 +2184,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2198,8 +2198,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2212,8 +2212,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -2231,8 +2231,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2245,8 +2245,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) @@ -2259,8 +2259,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let object = transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) @@ -2288,8 +2288,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2314,8 +2314,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2340,8 +2340,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = transaction.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -2361,8 +2361,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2387,8 +2387,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2413,8 +2413,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = transaction.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -2434,8 +2434,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -2452,8 +2452,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -2470,8 +2470,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -2505,8 +2505,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2528,8 +2528,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2551,8 +2551,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = transaction.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -2572,8 +2572,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2597,8 +2597,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2622,8 +2622,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = transaction.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -2643,8 +2643,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2668,8 +2668,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2693,8 +2693,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = transaction.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -2714,7 +2714,7 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -2731,7 +2731,7 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] let objects = self.expectLogger([.logWarning]) { @@ -2765,8 +2765,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2788,8 +2788,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2811,8 +2811,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = transaction.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -2832,8 +2832,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2857,8 +2857,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2882,8 +2882,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = transaction.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -2903,8 +2903,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2928,8 +2928,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] let objects = transaction.fetchAll(from, fetchClauses) @@ -2953,8 +2953,8 @@ final class FetchTests: BaseTestDataTestCase { do { let fetchClauses: [FetchClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] let objects = transaction.fetchAll(from, fetchClauses) XCTAssertNotNil(objects) @@ -2985,8 +2985,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -2996,8 +2996,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3007,8 +3007,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -3024,8 +3024,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3035,8 +3035,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3046,8 +3046,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -3065,8 +3065,8 @@ final class FetchTests: BaseTestDataTestCase { transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -3077,8 +3077,8 @@ final class FetchTests: BaseTestDataTestCase { transaction.fetchCount( from, - Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -3089,8 +3089,8 @@ final class FetchTests: BaseTestDataTestCase { transaction.fetchCount( from, - Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -3116,8 +3116,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3127,8 +3127,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3138,8 +3138,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -3155,8 +3155,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3166,8 +3166,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3177,8 +3177,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -3194,8 +3194,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3205,8 +3205,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3216,8 +3216,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -3235,8 +3235,8 @@ final class FetchTests: BaseTestDataTestCase { transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -3247,8 +3247,8 @@ final class FetchTests: BaseTestDataTestCase { transaction.fetchCount( from, - Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -3259,8 +3259,8 @@ final class FetchTests: BaseTestDataTestCase { transaction.fetchCount( from, - Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) + Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ) } XCTAssertNil(count) @@ -3286,8 +3286,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3297,8 +3297,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3308,8 +3308,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -3325,8 +3325,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3336,8 +3336,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3347,8 +3347,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) @@ -3364,8 +3364,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3375,8 +3375,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), + Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) XCTAssertNotNil(count) @@ -3386,8 +3386,8 @@ final class FetchTests: BaseTestDataTestCase { let count = transaction.fetchCount( from, - Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) XCTAssertNotNil(count) XCTAssertEqual(count, 0) diff --git a/CoreStoreTests/ImportTests.swift b/CoreStoreTests/ImportTests.swift index e328891..05cb7fc 100644 --- a/CoreStoreTests/ImportTests.swift +++ b/CoreStoreTests/ImportTests.swift @@ -444,7 +444,7 @@ class ImportTests: BaseTestDataTestCase { XCTAssertNil(object) XCTAssertEqual(transaction.fetchCount(From()), 5) - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) XCTAssertNotNil(existingObjects) XCTAssertEqual(existingObjects?.count, 1) @@ -620,7 +620,7 @@ class ImportTests: BaseTestDataTestCase { errorExpectation.fulfill() XCTAssertEqual(transaction.fetchCount(From()), 6) - let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) + let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertNil(object?.testBoolean) @@ -659,7 +659,7 @@ class ImportTests: BaseTestDataTestCase { errorExpectation.fulfill() XCTAssertEqual(transaction.fetchCount(From()), 6) - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) XCTAssertNotNil(existingObjects) XCTAssertEqual(existingObjects?.count, 1) @@ -745,7 +745,7 @@ class ImportTests: BaseTestDataTestCase { XCTAssertEqual(object?.testData, ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!) XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!) - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) + let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) XCTAssertNotNil(existingObjects) XCTAssertEqual(existingObjects?.count, 1) @@ -866,8 +866,8 @@ class ImportTests: BaseTestDataTestCase { errorExpectation.fulfill() XCTAssertEqual(transaction.fetchCount(From()), 5) - XCTAssertNil(transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))) - XCTAssertNil(transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 107))) + XCTAssertNil(transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))) + XCTAssertNil(transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 107))) } transaction.unsafeContext().reset() self.checkExpectationsImmediately() @@ -910,7 +910,7 @@ class ImportTests: BaseTestDataTestCase { errorExpectation.fulfill() - let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) + let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertNil(object?.testBoolean) @@ -953,7 +953,7 @@ class ImportTests: BaseTestDataTestCase { errorExpectation.fulfill() XCTAssertEqual(transaction.fetchCount(From()), 5) - let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 105)) XCTAssertEqual(object?.testBoolean, NSNumber(value: true)) @@ -963,7 +963,7 @@ class ImportTests: BaseTestDataTestCase { XCTAssertEqual(object?.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!) XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!) - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) XCTAssertNotNil(existingObjects) XCTAssertEqual(existingObjects?.count, 1) @@ -1032,7 +1032,7 @@ class ImportTests: BaseTestDataTestCase { XCTAssertEqual(object.testData, dictionary[(#keyPath(TestEntity1.testData))] as? Data) XCTAssertEqual(object.testDate, dictionary[(#keyPath(TestEntity1.testDate))] as? Date) } - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) XCTAssertNotNil(existingObjects) XCTAssertEqual(existingObjects?.count, 1) diff --git a/CoreStoreTests/ListObserverTests.swift b/CoreStoreTests/ListObserverTests.swift index 5e81c23..64ad58f 100644 --- a/CoreStoreTests/ListObserverTests.swift +++ b/CoreStoreTests/ListObserverTests.swift @@ -43,7 +43,7 @@ class ListObserverTests: BaseTestDataTestCase { let monitor = stack.monitorSectionedList( From(), SectionBy(#keyPath(TestEntity1.testBoolean)), - OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) ) monitor.addObserver(observer) @@ -171,7 +171,7 @@ class ListObserverTests: BaseTestDataTestCase { let monitor = stack.monitorSectionedList( From(), SectionBy(#keyPath(TestEntity1.testBoolean)), - OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) ) monitor.addObserver(observer) @@ -270,7 +270,7 @@ class ListObserverTests: BaseTestDataTestCase { if let object = transaction.fetchOne( From(), - Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) { + Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) { object.testNumber = NSNumber(value: 11) object.testDecimal = NSDecimalNumber(string: "11") @@ -284,7 +284,7 @@ class ListObserverTests: BaseTestDataTestCase { } if let object = transaction.fetchOne( From(), - Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) { + Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) { object.testNumber = NSNumber(value: 22) object.testDecimal = NSDecimalNumber(string: "22") @@ -323,7 +323,7 @@ class ListObserverTests: BaseTestDataTestCase { let monitor = stack.monitorSectionedList( From(), SectionBy(#keyPath(TestEntity1.testBoolean)), - OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) ) monitor.addObserver(observer) @@ -396,7 +396,7 @@ class ListObserverTests: BaseTestDataTestCase { if let object = transaction.fetchOne( From(), - Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) { + Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) { object.testBoolean = NSNumber(value: true) } @@ -431,7 +431,7 @@ class ListObserverTests: BaseTestDataTestCase { let monitor = stack.monitorSectionedList( From(), SectionBy(#keyPath(TestEntity1.testBoolean)), - OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) + OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) ) monitor.addObserver(observer) @@ -528,7 +528,7 @@ class ListObserverTests: BaseTestDataTestCase { let count = transaction.deleteAll( From(), - Where(#keyPath(TestEntity1.testBoolean), isEqualTo: false) + Where(#keyPath(TestEntity1.testBoolean), isEqualTo: false) ) XCTAssertEqual(count, 2) return transaction.hasChanges diff --git a/CoreStoreTests/ObjectObserverTests.swift b/CoreStoreTests/ObjectObserverTests.swift index c23ace9..c544f3d 100644 --- a/CoreStoreTests/ObjectObserverTests.swift +++ b/CoreStoreTests/ObjectObserverTests.swift @@ -43,7 +43,7 @@ class ObjectObserverTests: BaseTestDataTestCase { guard let object = stack.fetchOne( From(), - Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { + Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { XCTFail() return @@ -140,7 +140,7 @@ class ObjectObserverTests: BaseTestDataTestCase { guard let object = stack.fetchOne( From(), - Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { + Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { XCTFail() return diff --git a/CoreStoreTests/OrderByTests.swift b/CoreStoreTests/OrderByTests.swift index 69af761..c1d861e 100644 --- a/CoreStoreTests/OrderByTests.swift +++ b/CoreStoreTests/OrderByTests.swift @@ -38,21 +38,21 @@ final class OrderByTests: XCTestCase { do { - let orderBy = OrderBy() - XCTAssertEqual(orderBy, OrderBy([NSSortDescriptor]())) - XCTAssertNotEqual(orderBy, OrderBy(NSSortDescriptor(key: "key", ascending: false))) + let orderBy = OrderBy() + XCTAssertEqual(orderBy, OrderBy([NSSortDescriptor]())) + XCTAssertNotEqual(orderBy, OrderBy(NSSortDescriptor(key: "key", ascending: false))) XCTAssertTrue(orderBy.sortDescriptors.isEmpty) } do { let sortDescriptor = NSSortDescriptor(key: "key1", ascending: true) - let orderBy = OrderBy(sortDescriptor) + let orderBy = OrderBy(sortDescriptor) XCTAssertEqual(orderBy, OrderBy(sortDescriptor)) - XCTAssertEqual(orderBy, OrderBy(.ascending("key1"))) - XCTAssertNotEqual(orderBy, OrderBy(.ascending("key2"))) - XCTAssertNotEqual(orderBy, OrderBy(.descending("key1"))) - XCTAssertNotEqual(orderBy, OrderBy(NSSortDescriptor(key: "key1", ascending: false))) - XCTAssertEqual(orderBy, OrderBy([sortDescriptor])) + XCTAssertEqual(orderBy, OrderBy(.ascending("key1"))) + XCTAssertNotEqual(orderBy, OrderBy(.ascending("key2"))) + XCTAssertNotEqual(orderBy, OrderBy(.descending("key1"))) + XCTAssertNotEqual(orderBy, OrderBy(NSSortDescriptor(key: "key1", ascending: false))) + XCTAssertEqual(orderBy, OrderBy([sortDescriptor])) XCTAssertEqual(orderBy.sortDescriptors, [sortDescriptor]) } do { @@ -61,76 +61,76 @@ final class OrderByTests: XCTestCase { NSSortDescriptor(key: "key1", ascending: true), NSSortDescriptor(key: "key2", ascending: false) ] - let orderBy = OrderBy(sortDescriptors) - XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) - XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) + let orderBy = OrderBy(sortDescriptors) + XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) + XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) XCTAssertNotEqual( orderBy, - OrderBy( + OrderBy( [ NSSortDescriptor(key: "key1", ascending: false), NSSortDescriptor(key: "key2", ascending: false) ] ) ) - XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) - XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) + XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) + XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors) } do { - let orderBy = OrderBy(.ascending("key1")) + let orderBy = OrderBy(.ascending("key1")) let sortDescriptor = NSSortDescriptor(key: "key1", ascending: true) - XCTAssertEqual(orderBy, OrderBy(sortDescriptor)) - XCTAssertEqual(orderBy, OrderBy(.ascending("key1"))) - XCTAssertNotEqual(orderBy, OrderBy(.descending("key1"))) - XCTAssertNotEqual(orderBy, OrderBy(.ascending("key2"))) - XCTAssertEqual(orderBy, OrderBy([sortDescriptor])) + XCTAssertEqual(orderBy, OrderBy(sortDescriptor)) + XCTAssertEqual(orderBy, OrderBy(.ascending("key1"))) + XCTAssertNotEqual(orderBy, OrderBy(.descending("key1"))) + XCTAssertNotEqual(orderBy, OrderBy(.ascending("key2"))) + XCTAssertEqual(orderBy, OrderBy([sortDescriptor])) XCTAssertEqual(orderBy.sortDescriptors, [sortDescriptor]) } do { - let orderBy = OrderBy(.ascending("key1"), .descending("key2")) + let orderBy = OrderBy(.ascending("key1"), .descending("key2")) let sortDescriptors = [ NSSortDescriptor(key: "key1", ascending: true), NSSortDescriptor(key: "key2", ascending: false) ] - XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) - XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) + XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) + XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) XCTAssertNotEqual( orderBy, - OrderBy( + OrderBy( [ NSSortDescriptor(key: "key1", ascending: false), NSSortDescriptor(key: "key2", ascending: false) ] ) ) - XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) - XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) + XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) + XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors) } do { - let sortKeys: [SortKey] = [.ascending("key1"), .descending("key2")] - let orderBy = OrderBy(sortKeys) + let sortKeys: [OrderBy.SortKey] = [.ascending("key1"), .descending("key2")] + let orderBy = OrderBy(sortKeys) let sortDescriptors = [ NSSortDescriptor(key: "key1", ascending: true), NSSortDescriptor(key: "key2", ascending: false) ] - XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) - XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) + XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) + XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) XCTAssertNotEqual( orderBy, - OrderBy( + OrderBy( [ NSSortDescriptor(key: "key1", ascending: false), NSSortDescriptor(key: "key2", ascending: false) ] ) ) - XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) - XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) + XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) + XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors) } } @@ -138,15 +138,15 @@ final class OrderByTests: XCTestCase { @objc dynamic func test_ThatOrderByClauseOperations_ComputeCorrectly() { - let orderBy1 = OrderBy(.ascending("key1")) - let orderBy2 = OrderBy(.descending("key2")) - let orderBy3 = OrderBy(.ascending("key3")) + let orderBy1 = OrderBy(.ascending("key1")) + let orderBy2 = OrderBy(.descending("key2")) + let orderBy3 = OrderBy(.ascending("key3")) do { let plusOrderBy = orderBy1 + orderBy2 + orderBy3 - XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"), .ascending("key3"))) - XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1")) + OrderBy(.descending("key2"), .ascending("key3"))) + XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"), .ascending("key3"))) + XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1")) + OrderBy(.descending("key2"), .ascending("key3"))) XCTAssertNotEqual(plusOrderBy, orderBy1 + orderBy3 + orderBy2) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1 + orderBy3) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy3 + orderBy1) @@ -158,14 +158,14 @@ final class OrderByTests: XCTestCase { var plusOrderBy = orderBy1 plusOrderBy += orderBy2 - XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"))) - XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1")) + OrderBy(.descending("key2"))) + XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"))) + XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1")) + OrderBy(.descending("key2"))) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1) XCTAssertEqual(plusOrderBy.sortDescriptors, orderBy1.sortDescriptors + orderBy2.sortDescriptors) plusOrderBy += orderBy3 - XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"), .ascending("key3"))) - XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2")) + OrderBy(.ascending("key3"))) + XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"), .ascending("key3"))) + XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2")) + OrderBy(.ascending("key3"))) XCTAssertNotEqual(plusOrderBy, orderBy1 + orderBy3 + orderBy2) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1 + orderBy3) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy3 + orderBy1) @@ -178,7 +178,7 @@ final class OrderByTests: XCTestCase { @objc dynamic func test_ThatOrderByClauses_ApplyToFetchRequestsCorrectly() { - let orderBy = OrderBy(.ascending("key")) + let orderBy = OrderBy(.ascending("key")) let request = CoreStoreFetchRequest() orderBy.applyToFetchRequest(request) XCTAssertNotNil(request.sortDescriptors) diff --git a/CoreStoreTests/QueryTests.swift b/CoreStoreTests/QueryTests.swift index 215061d..a82b963 100644 --- a/CoreStoreTests/QueryTests.swift +++ b/CoreStoreTests/QueryTests.swift @@ -43,7 +43,7 @@ class QueryTests: BaseTestDataTestCase { let from = From(configurations) let queryClauses: [QueryClause] = [ - Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101) + Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101) ] do { @@ -227,8 +227,8 @@ class QueryTests: BaseTestDataTestCase { let from = From(configurations) let queryClauses: [QueryClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] do { @@ -406,7 +406,7 @@ class QueryTests: BaseTestDataTestCase { let from = From(configurations) let queryClauses: [QueryClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) ] do { @@ -583,7 +583,7 @@ class QueryTests: BaseTestDataTestCase { let from = From(configurations) let queryClauses: [QueryClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) ] do { @@ -767,7 +767,7 @@ class QueryTests: BaseTestDataTestCase { let from = From(configurations) let queryClauses: [QueryClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) ] do { @@ -951,7 +951,7 @@ class QueryTests: BaseTestDataTestCase { let from = From(configurations) let queryClauses: [QueryClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) ] do { @@ -1129,7 +1129,7 @@ class QueryTests: BaseTestDataTestCase { let from = From(configurations) let queryClauses: [QueryClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) ] do { @@ -1297,8 +1297,8 @@ class QueryTests: BaseTestDataTestCase { let from = From(configurations) let queryClauses: [QueryClause] = [ - Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), - OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) + Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), + OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] do { diff --git a/CoreStoreTests/TransactionTests.swift b/CoreStoreTests/TransactionTests.swift index 36347b3..c138f5b 100644 --- a/CoreStoreTests/TransactionTests.swift +++ b/CoreStoreTests/TransactionTests.swift @@ -396,7 +396,7 @@ final class TransactionTests: BaseTestCase { let observer = TestListObserver() let monitor = stack.monitorList( From(), - OrderBy(.ascending("testEntityID")) + OrderBy(.ascending("testEntityID")) ) monitor.addObserver(observer) diff --git a/CoreStoreTests/WhereTests.swift b/CoreStoreTests/WhereTests.swift index 307e404..4722b37 100644 --- a/CoreStoreTests/WhereTests.swift +++ b/CoreStoreTests/WhereTests.swift @@ -31,12 +31,12 @@ import CoreStore // MARK: - XCTAssertAllEqual -private func XCTAssertAllEqual(_ whereClauses: Where...) { +private func XCTAssertAllEqual(_ whereClauses: Where...) { XCTAssertAllEqual(whereClauses) } -private func XCTAssertAllEqual(_ whereClauses: [Where]) { +private func XCTAssertAllEqual(_ whereClauses: [Where]) { for i in whereClauses.indices { @@ -57,51 +57,51 @@ final class WhereTests: XCTestCase { do { - let whereClause = Where() - XCTAssertEqual(whereClause, Where(true)) - XCTAssertNotEqual(whereClause, Where(false)) + let whereClause = Where() + XCTAssertEqual(whereClause, Where(true)) + XCTAssertNotEqual(whereClause, Where(false)) XCTAssertEqual(whereClause.predicate, NSPredicate(value: true)) } do { - let whereClause = Where(true) - XCTAssertEqual(whereClause, Where()) - XCTAssertNotEqual(whereClause, Where(false)) + let whereClause = Where(true) + XCTAssertEqual(whereClause, Where()) + XCTAssertNotEqual(whereClause, Where(false)) XCTAssertEqual(whereClause.predicate, NSPredicate(value: true)) } do { let predicate = NSPredicate(format: "%K == %@", "key", "value") - let whereClause = Where(predicate) - XCTAssertEqual(whereClause, Where(predicate)) + let whereClause = Where(predicate) + XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause.predicate, predicate) } do { - let whereClause = Where("%K == %@", "key", "value") + let whereClause = Where("%K == %@", "key", "value") let predicate = NSPredicate(format: "%K == %@", "key", "value") - XCTAssertEqual(whereClause, Where(predicate)) + XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause.predicate, predicate) } do { - let whereClause = Where("%K == %@", argumentArray: ["key", "value"]) + let whereClause = Where("%K == %@", argumentArray: ["key", "value"]) let predicate = NSPredicate(format: "%K == %@", "key", "value") - XCTAssertEqual(whereClause, Where(predicate)) + XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause.predicate, predicate) } do { - let whereClause = Where("key", isEqualTo: "value") + let whereClause = Where("key", isEqualTo: "value") let predicate = NSPredicate(format: "%K == %@", "key", "value") - XCTAssertEqual(whereClause, Where(predicate)) + XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause.predicate, predicate) } do { - let whereClause = Where("key", isMemberOf: ["value1", "value2", "value3"]) + let whereClause = Where("key", isMemberOf: ["value1", "value2", "value3"]) let predicate = NSPredicate(format: "%K IN %@", "key", ["value1", "value2", "value3"]) - XCTAssertEqual(whereClause, Where(predicate)) + XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause.predicate, predicate) } } @@ -113,112 +113,112 @@ final class WhereTests: XCTestCase { let value: Int = 100 XCTAssertAllEqual( - Where("%K == %d", "key", value), - Where("%K == %d", "key", value as AnyObject), - Where("%K == %d", "key", NSNumber(value: value)), - Where("%K == %@", "key", value), - Where("%K == %@", "key", value as AnyObject), - Where("%K == %@", "key", NSNumber(value: value)), - Where("key", isEqualTo: value), - Where("key", isEqualTo: NSNumber(value: value)) + Where("%K == %d", "key", value), + Where("%K == %d", "key", value as AnyObject), + Where("%K == %d", "key", NSNumber(value: value)), + Where("%K == %@", "key", value), + Where("%K == %@", "key", value as AnyObject), + Where("%K == %@", "key", NSNumber(value: value)), + Where("key", isEqualTo: value), + Where("key", isEqualTo: NSNumber(value: value)) ) } do { let value = NSNumber(value: 100) XCTAssertAllEqual( - Where("%K == %d", "key", value), - Where("%K == %d", "key", value as AnyObject), - Where("%K == %d", "key", value.intValue), - Where("%K == %@", "key", value), - Where("%K == %@", "key", value as AnyObject), - Where("%K == %@", "key", value.intValue), - Where("key", isEqualTo: value), - Where("key", isEqualTo: value.intValue) + Where("%K == %d", "key", value), + Where("%K == %d", "key", value as AnyObject), + Where("%K == %d", "key", value.intValue), + Where("%K == %@", "key", value), + Where("%K == %@", "key", value as AnyObject), + Where("%K == %@", "key", value.intValue), + Where("key", isEqualTo: value), + Where("key", isEqualTo: value.intValue) ) } do { let value: Int64 = Int64.max XCTAssertAllEqual( - Where("%K == %d", "key", value), - Where("%K == %d", "key", value as AnyObject), - Where("%K == %d", "key", NSNumber(value: value)), - Where("%K == %@", "key", value), - Where("%K == %@", "key", value as AnyObject), - Where("%K == %@", "key", NSNumber(value: value)), - Where("key", isEqualTo: value), - Where("key", isEqualTo: NSNumber(value: value)) + Where("%K == %d", "key", value), + Where("%K == %d", "key", value as AnyObject), + Where("%K == %d", "key", NSNumber(value: value)), + Where("%K == %@", "key", value), + Where("%K == %@", "key", value as AnyObject), + Where("%K == %@", "key", NSNumber(value: value)), + Where("key", isEqualTo: value), + Where("key", isEqualTo: NSNumber(value: value)) ) } do { let value = NSNumber(value: Int64.max) XCTAssertAllEqual( - Where("%K == %d", "key", value), - Where("%K == %d", "key", value as AnyObject), - Where("%K == %d", "key", value.int64Value), - Where("%K == %@", "key", value), - Where("%K == %@", "key", value as AnyObject), - Where("%K == %@", "key", value.int64Value), - Where("key", isEqualTo: value), - Where("key", isEqualTo: value.int64Value) + Where("%K == %d", "key", value), + Where("%K == %d", "key", value as AnyObject), + Where("%K == %d", "key", value.int64Value), + Where("%K == %@", "key", value), + Where("%K == %@", "key", value as AnyObject), + Where("%K == %@", "key", value.int64Value), + Where("key", isEqualTo: value), + Where("key", isEqualTo: value.int64Value) ) } do { let value: String = "value" XCTAssertAllEqual( - Where("%K == %s", "key", value), - Where("%K == %s", "key", value as AnyObject), - Where("%K == %s", "key", NSString(string: value)), - Where("%K == %@", "key", value), - Where("%K == %@", "key", value as AnyObject), - Where("%K == %@", "key", NSString(string: value)), - Where("key", isEqualTo: value), - Where("key", isEqualTo: value as NSString), - Where("key", isEqualTo: NSString(string: value)) + Where("%K == %s", "key", value), + Where("%K == %s", "key", value as AnyObject), + Where("%K == %s", "key", NSString(string: value)), + Where("%K == %@", "key", value), + Where("%K == %@", "key", value as AnyObject), + Where("%K == %@", "key", NSString(string: value)), + Where("key", isEqualTo: value), + Where("key", isEqualTo: value as NSString), + Where("key", isEqualTo: NSString(string: value)) ) } do { let value = NSString(string: "value") XCTAssertAllEqual( - Where("%K == %s", "key", value), - Where("%K == %s", "key", value as String), - Where("%K == %s", "key", value as String as AnyObject), - Where("%K == %@", "key", value), - Where("%K == %@", "key", value as String), - Where("%K == %@", "key", value as String as AnyObject), - Where("key", isEqualTo: value), - Where("key", isEqualTo: value as String), - Where("key", isEqualTo: value as String as NSString) + Where("%K == %s", "key", value), + Where("%K == %s", "key", value as String), + Where("%K == %s", "key", value as String as AnyObject), + Where("%K == %@", "key", value), + Where("%K == %@", "key", value as String), + Where("%K == %@", "key", value as String as AnyObject), + Where("key", isEqualTo: value), + Where("key", isEqualTo: value as String), + Where("key", isEqualTo: value as String as NSString) ) } do { let value: [Int] = [100, 200] XCTAssertAllEqual( - Where("%K IN %@", "key", value), - Where("%K IN %@", "key", value as AnyObject), - Where("%K IN %@", "key", value as [AnyObject]), - Where("%K IN %@", "key", value as NSArray), - Where("%K IN %@", "key", NSArray(array: value)), - Where("%K IN %@", "key", value as AnyObject as! NSArray), - Where("key", isMemberOf: value) + Where("%K IN %@", "key", value), + Where("%K IN %@", "key", value as AnyObject), + Where("%K IN %@", "key", value as [AnyObject]), + Where("%K IN %@", "key", value as NSArray), + Where("%K IN %@", "key", NSArray(array: value)), + Where("%K IN %@", "key", value as AnyObject as! NSArray), + Where("key", isMemberOf: value) ) } do { let value: [Int64] = [Int64.min, 100, Int64.max] XCTAssertAllEqual( - Where("%K IN %@", "key", value), - Where("%K IN %@", "key", value as AnyObject), - Where("%K IN %@", "key", value as [AnyObject]), - Where("%K IN %@", "key", value as NSArray), - Where("%K IN %@", "key", NSArray(array: value)), - Where("%K IN %@", "key", value as AnyObject as! NSArray), - Where("key", isMemberOf: value) + Where("%K IN %@", "key", value), + Where("%K IN %@", "key", value as AnyObject), + Where("%K IN %@", "key", value as [AnyObject]), + Where("%K IN %@", "key", value as NSArray), + Where("%K IN %@", "key", NSArray(array: value)), + Where("%K IN %@", "key", value as AnyObject as! NSArray), + Where("key", isMemberOf: value) ) } } @@ -226,9 +226,9 @@ final class WhereTests: XCTestCase { @objc dynamic func test_ThatWhereClauseOperations_ComputeCorrectly() { - let whereClause1 = Where("key1", isEqualTo: "value1") - let whereClause2 = Where("key2", isEqualTo: "value2") - let whereClause3 = Where("key3", isEqualTo: "value3") + let whereClause1 = Where("key1", isEqualTo: "value1") + let whereClause2 = Where("key2", isEqualTo: "value2") + let whereClause3 = Where("key3", isEqualTo: "value3") do { @@ -259,8 +259,8 @@ final class WhereTests: XCTestCase { do { let andWhere = whereClause1 && whereClause2 && whereClause3 - let noneWhere: Where? = nil - let someWhere: Where? = Where("key4", isEqualTo: "value4") + let noneWhere: Where? = nil + let someWhere: Where? = Where("key4", isEqualTo: "value4") let finalNoneWhere = andWhere && noneWhere @@ -290,8 +290,8 @@ final class WhereTests: XCTestCase { do { let orWhere = whereClause1 || whereClause2 || whereClause3 - let noneWhere: Where? = nil - let someWhere: Where? = Where("key4", isEqualTo: "value4") + let noneWhere: Where? = nil + let someWhere: Where? = Where("key4", isEqualTo: "value4") let finalNoneWhere = orWhere && noneWhere @@ -307,7 +307,7 @@ final class WhereTests: XCTestCase { @objc dynamic func test_ThatWhereClauses_ApplyToFetchRequestsCorrectly() { - let whereClause = Where("key", isEqualTo: "value") + let whereClause = Where("key", isEqualTo: "value") let request = CoreStoreFetchRequest() whereClause.applyToFetchRequest(request) XCTAssertNotNil(request.predicate) diff --git a/Sources/AsynchronousDataTransaction.swift b/Sources/AsynchronousDataTransaction.swift index 0bb75fb..c3601d4 100644 --- a/Sources/AsynchronousDataTransaction.swift +++ b/Sources/AsynchronousDataTransaction.swift @@ -100,7 +100,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type. */ - public override func create(_ into: Into) -> T { + public override func create(_ into: Into) -> D { CoreStore.assert( !self.isCommitted, @@ -116,7 +116,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. */ - public override func edit(_ object: T?) -> T? { + public override func edit(_ object: D?) -> D? { CoreStore.assert( !self.isCommitted, @@ -133,7 +133,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter objectID: the `NSManagedObjectID` for the object to be edited - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. */ - public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { + public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> D? { CoreStore.assert( !self.isCommitted, @@ -148,7 +148,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter object: the `NSManagedObject` or `CoreStoreObject` to be deleted */ - public override func delete(_ object: T?) { + public override func delete(_ object: D?) { CoreStore.assert( !self.isCommitted, @@ -165,7 +165,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter object2: another `DynamicObject` to be deleted - parameter objects: other `DynamicObject`s to be deleted */ - public override func delete(_ object1: T?, _ object2: T?, _ objects: T?...) { + public override func delete(_ object1: D?, _ object2: D?, _ objects: D?...) { CoreStore.assert( !self.isCommitted, diff --git a/Sources/BaseDataTransaction+Importing.swift b/Sources/BaseDataTransaction+Importing.swift index acdee54..4905fa5 100644 --- a/Sources/BaseDataTransaction+Importing.swift +++ b/Sources/BaseDataTransaction+Importing.swift @@ -39,9 +39,9 @@ public extension BaseDataTransaction { - throws: an `Error` thrown from any of the `ImportableObject` methods - returns: the created `ImportableObject` instance, or `nil` if the import was ignored */ - public func importObject( - _ into: Into, - source: T.ImportSource) throws -> T? { + public func importObject( + _ into: Into, + source: D.ImportSource) throws -> D? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -69,9 +69,9 @@ public extension BaseDataTransaction { - parameter source: the object to import values from - throws: an `Error` thrown from any of the `ImportableObject` methods */ - public func importObject( - _ object: T, - source: T.ImportSource) throws { + public func importObject( + _ object: D, + source: D.ImportSource) throws { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -97,9 +97,9 @@ public extension BaseDataTransaction { - throws: an `Error` thrown from any of the `ImportableObject` methods - returns: the array of created `ImportableObject` instances */ - public func importObjects( - _ into: Into, - sourceArray: S) throws -> [T] where S.Iterator.Element == T.ImportSource { + public func importObjects( + _ into: Into, + sourceArray: S) throws -> [D] where S.Iterator.Element == D.ImportSource { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -108,7 +108,7 @@ public extension BaseDataTransaction { return try autoreleasepool { - return try sourceArray.flatMap { (source) -> T? in + return try sourceArray.flatMap { (source) -> D? in let entityType = into.entityClass guard entityType.shouldInsert(from: source, in: self) else { @@ -133,9 +133,9 @@ public extension BaseDataTransaction { - throws: an `Error` thrown from any of the `ImportableUniqueObject` methods - returns: the created/updated `ImportableUniqueObject` instance, or `nil` if the import was ignored */ - public func importUniqueObject( - _ into: Into, - source: T.ImportSource) throws -> T? { + public func importUniqueObject( + _ into: Into, + source: D.ImportSource) throws -> D? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -151,7 +151,7 @@ public extension BaseDataTransaction { return nil } - if let object = self.fetchOne(From(entityType), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) { + if let object = self.fetchOne(From(entityType), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) { guard entityType.shouldUpdate(from: source, in: self) else { @@ -185,10 +185,10 @@ public extension BaseDataTransaction { - throws: an `Error` thrown from any of the `ImportableUniqueObject` methods - returns: the array of created/updated `ImportableUniqueObject` instances */ - public func importUniqueObjects( - _ into: Into, + public func importUniqueObjects( + _ into: Into, sourceArray: S, - preProcess: @escaping (_ mapping: [T.UniqueIDType: T.ImportSource]) throws -> [T.UniqueIDType: T.ImportSource] = { $0 }) throws -> [T] where S.Iterator.Element == T.ImportSource { + preProcess: @escaping (_ mapping: [D.UniqueIDType: D.ImportSource]) throws -> [D.UniqueIDType: D.ImportSource] = { $0 }) throws -> [D] where S.Iterator.Element == D.ImportSource { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -198,10 +198,10 @@ public extension BaseDataTransaction { return try autoreleasepool { let entityType = into.entityClass - var importSourceByID = Dictionary() + var importSourceByID = Dictionary() let sortedIDs = try autoreleasepool { - return try sourceArray.flatMap { (source) -> T.UniqueIDType? in + return try sourceArray.flatMap { (source) -> D.UniqueIDType? in guard let uniqueIDValue = try entityType.uniqueID(from: source, in: self) else { @@ -214,12 +214,12 @@ public extension BaseDataTransaction { importSourceByID = try autoreleasepool { try preProcess(importSourceByID) } - var existingObjectsByID = Dictionary() - self.fetchAll(From(entityType), Where(entityType.uniqueIDKeyPath, isMemberOf: sortedIDs))? + var existingObjectsByID = Dictionary() + self.fetchAll(From(entityType), Where(entityType.uniqueIDKeyPath, isMemberOf: sortedIDs))? .forEach { existingObjectsByID[$0.uniqueIDValue] = $0 } - var processedObjectIDs = Set() - var result = [T]() + var processedObjectIDs = Set() + var result = [D]() for objectID in sortedIDs where !processedObjectIDs.contains(objectID) { diff --git a/Sources/BaseDataTransaction+Querying.swift b/Sources/BaseDataTransaction+Querying.swift index 776507f..8cc55b1 100644 --- a/Sources/BaseDataTransaction+Querying.swift +++ b/Sources/BaseDataTransaction+Querying.swift @@ -39,13 +39,12 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - returns: the number of `DynamicObject`s deleted */ @discardableResult - public func deleteAll(_ from: From, _ deleteClauses: DeleteClause...) -> Int? { + public func deleteAll(_ from: From, _ deleteClauses: DeleteClause...) -> Int? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.deleteAll(from, deleteClauses) } @@ -57,14 +56,32 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - returns: the number of `DynamicObject`s deleted */ @discardableResult - public func deleteAll(_ from: From, _ deleteClauses: [DeleteClause]) -> Int? { + public func deleteAll(_ from: From, _ deleteClauses: [DeleteClause]) -> Int? { + + CoreStore.assert( + self.isRunningInAllowedQueue(), + "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." + ) + return self.context.deleteAll(from, deleteClauses) + } + + /** + Deletes all `DynamicObject`s that satisfy the specified conditions. + ``` + transaction.deleteAll(From().where(\.age > 50) + ``` + - parameter clauseChain: a `FetchChainableBuilderType` clause chain created from a `From` clause + - returns: the number of `DynamicObject`s deleted + */ + @discardableResult + public func deleteAll(_ clauseChain: B) -> Int? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.deleteAll(from, deleteClauses) + return self.context.deleteAll(clauseChain.from, clauseChain.fetchClauses) } @@ -76,7 +93,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter object: a reference to the object created/fetched outside the transaction - returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found. */ - public func fetchExisting(_ object: T) -> T? { + public func fetchExisting(_ object: D) -> D? { return self.context.fetchExisting(object) } @@ -87,7 +104,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter objectID: the `NSManagedObjectID` for the object - returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found. */ - public func fetchExisting(_ objectID: NSManagedObjectID) -> T? { + public func fetchExisting(_ objectID: NSManagedObjectID) -> D? { return self.context.fetchExisting(objectID) } @@ -98,7 +115,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter objects: an array of `DynamicObject`s created/fetched outside the transaction - returns: the `DynamicObject` array for objects that exists in the transaction */ - public func fetchExisting(_ objects: S) -> [T] where S.Iterator.Element == T { + public func fetchExisting(_ objects: S) -> [D] where S.Iterator.Element == D { return self.context.fetchExisting(objects) } @@ -109,7 +126,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter objectIDs: the `NSManagedObjectID` array for the objects - returns: the `DynamicObject` array for objects that exists in the transaction */ - public func fetchExisting(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { + public func fetchExisting(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID { return self.context.fetchExisting(objectIDs) } @@ -121,7 +138,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> D? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -137,7 +154,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> D? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -146,6 +163,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { return self.context.fetchOne(from, fetchClauses) } + // TODO: docs + public func fetchOne(_ clauseChain: B) -> B.ObjectType? { + + CoreStore.assert( + self.isRunningInAllowedQueue(), + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + ) + return self.context.fetchOne(clauseChain) + } + /** Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -153,7 +180,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [D]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -169,7 +196,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [D]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -178,6 +205,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { return self.context.fetchAll(from, fetchClauses) } + // TODO: docs + public func fetchAll(_ clauseChain: B) -> [B.ObjectType]? { + + CoreStore.assert( + self.isRunningInAllowedQueue(), + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + ) + return self.context.fetchAll(clauseChain) + } + /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -185,7 +222,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -201,7 +238,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -210,6 +247,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { return self.context.fetchCount(from, fetchClauses) } + // TODO: docs + public func fetchCount(_ clauseChain: B) -> Int? { + + CoreStore.assert( + self.isRunningInAllowedQueue(), + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + ) + return self.context.fetchCount(clauseChain) + } + /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -217,7 +264,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -233,7 +280,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -242,6 +289,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { return self.context.fetchObjectID(from, fetchClauses) } + // TODO: docs + public func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { + + CoreStore.assert( + self.isRunningInAllowedQueue(), + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + ) + return self.context.fetchObjectID(clauseChain) + } + /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -249,7 +306,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -265,7 +322,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -274,6 +331,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { return self.context.fetchObjectIDs(from, fetchClauses) } + // TODO: docs + public func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { + + CoreStore.assert( + self.isRunningInAllowedQueue(), + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + ) + return self.context.fetchObjectIDs(clauseChain) + } + // MARK: QueryableSource @@ -287,7 +354,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -306,7 +373,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -325,7 +392,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -344,7 +411,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { CoreStore.assert( self.isRunningInAllowedQueue(), diff --git a/Sources/BaseDataTransaction.swift b/Sources/BaseDataTransaction.swift index 3a657f7..5af87d1 100644 --- a/Sources/BaseDataTransaction.swift +++ b/Sources/BaseDataTransaction.swift @@ -50,7 +50,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type. */ - public func create(_ into: Into) -> T { + public func create(_ into: Into) -> D { let entityClass = into.entityClass CoreStore.assert( @@ -121,7 +121,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter object: the `NSManagedObject` type to be edited - returns: an editable proxy for the specified `NSManagedObject`. */ - public func edit(_ object: T?) -> T? { + public func edit(_ object: D?) -> D? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -141,7 +141,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter objectID: the `NSManagedObjectID` for the object to be edited - returns: an editable proxy for the specified `NSManagedObject`. */ - public func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { + public func edit(_ into: Into, _ objectID: NSManagedObjectID) -> D? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -160,7 +160,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter object: the `NSManagedObject` to be deleted */ - public func delete(_ object: T?) { + public func delete(_ object: D?) { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -179,7 +179,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter object2: another `NSManagedObject` to be deleted - parameter objects: other `NSManagedObject`s to be deleted */ - public func delete(_ object1: T?, _ object2: T?, _ objects: T?...) { + public func delete(_ object1: D?, _ object2: D?, _ objects: D?...) { self.delete(([object1, object2] + objects).flatMap { $0 }) } @@ -220,7 +220,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter entity: the `DynamicObject` subclass to filter - returns: a `Set` of pending `DynamicObject`s of the specified type that were inserted to the transaction. */ - public func insertedObjects(_ entity: T.Type) -> Set { + public func insertedObjects(_ entity: D.Type) -> Set { CoreStore.assert( self.transactionQueue.cs_isCurrentExecutionContext(), @@ -257,7 +257,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter entity: the `DynamicObject` subclass to filter - returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction. */ - public func insertedObjectIDs(_ entity: T.Type) -> Set { + public func insertedObjectIDs(_ entity: D.Type) -> Set { CoreStore.assert( self.transactionQueue.cs_isCurrentExecutionContext(), @@ -276,7 +276,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter entity: the `DynamicObject` subclass to filter - returns: a `Set` of pending `DynamicObject`s of the specified type that were updated in the transaction. */ - public func updatedObjects(_ entity: T.Type) -> Set { + public func updatedObjects(_ entity: D.Type) -> Set { CoreStore.assert( self.transactionQueue.cs_isCurrentExecutionContext(), @@ -313,7 +313,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter entity: the `DynamicObject` subclass to filter - returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction. */ - public func updatedObjectIDs(_ entity: T.Type) -> Set { + public func updatedObjectIDs(_ entity: D.Type) -> Set { CoreStore.assert( self.transactionQueue.cs_isCurrentExecutionContext(), @@ -332,7 +332,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter entity: the `DynamicObject` subclass to filter - returns: a `Set` of pending `DynamicObject`s of the specified type that were deleted from the transaction. */ - public func deletedObjects(_ entity: T.Type) -> Set { + public func deletedObjects(_ entity: D.Type) -> Set { CoreStore.assert( self.transactionQueue.cs_isCurrentExecutionContext(), @@ -370,7 +370,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter entity: the `DynamicObject` subclass to filter - returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction. */ - public func deletedObjectIDs(_ entity: T.Type) -> Set { + public func deletedObjectIDs(_ entity: D.Type) -> Set { CoreStore.assert( self.transactionQueue.cs_isCurrentExecutionContext(), diff --git a/Sources/CSFrom.swift b/Sources/CSFrom.swift index fca0c17..50d9d6c 100644 --- a/Sources/CSFrom.swift +++ b/Sources/CSFrom.swift @@ -145,7 +145,7 @@ public final class CSFrom: NSObject { public let bridgeToSwift: From - public init(_ swiftValue: From) { + public init(_ swiftValue: From) { self.bridgeToSwift = swiftValue.downcast() super.init() @@ -155,7 +155,7 @@ public final class CSFrom: NSObject { // MARK: - From -extension From where T: NSManagedObject { +extension From where D: NSManagedObject { // MARK: CoreStoreSwiftType diff --git a/Sources/CSInto.swift b/Sources/CSInto.swift index 0510b32..6f3687f 100644 --- a/Sources/CSInto.swift +++ b/Sources/CSInto.swift @@ -112,7 +112,7 @@ public final class CSInto: NSObject { public let bridgeToSwift: Into - public required init(_ swiftValue: Into) { + public required init(_ swiftValue: Into) { self.bridgeToSwift = swiftValue.downcast() super.init() @@ -122,7 +122,7 @@ public final class CSInto: NSObject { // MARK: - Into -extension Into where T: NSManagedObject { +extension Into where D: NSManagedObject { // MARK: CoreStoreSwiftType diff --git a/Sources/CSOrderBy.swift b/Sources/CSOrderBy.swift index a7928ff..403fbfc 100644 --- a/Sources/CSOrderBy.swift +++ b/Sources/CSOrderBy.swift @@ -35,7 +35,7 @@ import CoreData - SeeAlso: `OrderBy` */ @objc -public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType { +public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause { /** The list of sort descriptors @@ -110,11 +110,11 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl // MARK: CoreStoreObjectiveCType - public let bridgeToSwift: OrderBy + public let bridgeToSwift: OrderBy - public init(_ swiftValue: OrderBy) { + public init(_ swiftValue: OrderBy) { - self.bridgeToSwift = swiftValue + self.bridgeToSwift = swiftValue.downcast() super.init() } } @@ -122,7 +122,7 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl // MARK: - OrderBy -extension OrderBy: CoreStoreSwiftType { +extension OrderBy where D: NSManagedObject { // MARK: CoreStoreSwiftType @@ -130,4 +130,12 @@ extension OrderBy: CoreStoreSwiftType { return CSOrderBy(self) } + + + // MARK: FilePrivate + + fileprivate func downcast() -> OrderBy { + + return OrderBy(self.sortDescriptors) + } } diff --git a/Sources/CSWhere.swift b/Sources/CSWhere.swift index f36ad16..0bd637b 100644 --- a/Sources/CSWhere.swift +++ b/Sources/CSWhere.swift @@ -35,7 +35,7 @@ import CoreData - SeeAlso: `Where` */ @objc -public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType { +public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause { /** The internal `NSPredicate` instance for the `Where` clause @@ -149,11 +149,11 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau // MARK: CoreStoreObjectiveCType - public let bridgeToSwift: Where + public let bridgeToSwift: Where - public init(_ swiftValue: Where) { + public init(_ swiftValue: Where) { - self.bridgeToSwift = swiftValue + self.bridgeToSwift = swiftValue.downcast() super.init() } } @@ -161,7 +161,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau // MARK: - Where -extension Where: CoreStoreSwiftType { +extension Where where D: NSManagedObject { // MARK: CoreStoreSwiftType @@ -169,4 +169,12 @@ extension Where: CoreStoreSwiftType { return CSWhere(self) } + + + // MARK: FilePrivate + + fileprivate func downcast() -> Where { + + return Where(self.predicate) + } } diff --git a/Sources/ChainedClauseBuilder.swift b/Sources/ChainedClauseBuilder.swift new file mode 100644 index 0000000..df13948 --- /dev/null +++ b/Sources/ChainedClauseBuilder.swift @@ -0,0 +1,320 @@ +// +// FetchCondition.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 + + +public protocol FetchChainableBuilderType { + + associatedtype ObjectType: DynamicObject + + var from: From { get set } + var fetchClauses: [FetchClause] { get set } +} + +public protocol QueryChainableBuilderType { + + associatedtype ObjectType: DynamicObject + associatedtype ResultType: SelectResultType + + var from: From { get set } + var select: Select { get set } + var groupBy: GroupBy { get set } + var fetchClauses: [FetchClause] { get set } +} + +public protocol SectionMonitorBuilderType { + + associatedtype ObjectType: DynamicObject + + var from: From { get set } + var sectionBy: SectionBy { get set } + var fetchClauses: [FetchClause] { get set } +} + + +// MARK: - FetchChainBuilder + +public struct FetchChainBuilder: FetchChainableBuilderType { + + // MARK: FetchChainableBuilderType + + public typealias ObjectType = D + + public var from: From + public var fetchClauses: [FetchClause] = [] +} + + +// MARK: - QueryChainBuilder + +public struct QueryChainBuilder: QueryChainableBuilderType { + + // MARK: QueryChainableBuilderType + + public typealias ObjectType = D + public typealias ResultType = R + + public var from: From + public var select: Select + public var groupBy: GroupBy + public var fetchClauses: [FetchClause] = [] +} + + +// MARK: - SectionMonitorChainBuilder + +public struct SectionMonitorChainBuilder: SectionMonitorBuilderType { + + // MARK: SectionMonitorBuilderType + + public var from: From + public var sectionBy: SectionBy + public var fetchClauses: [FetchClause] = [] +} + + +// MARK: - From + +public extension From { + + public func select(_ resultType: R.Type, _ selectTerm: SelectTerm, _ selectTerms: SelectTerm...) -> QueryChainBuilder { + + return self.select(resultType, [selectTerm] + selectTerms) + } + + public func select(_ resultType: R.Type, _ selectTerms: [SelectTerm]) -> QueryChainBuilder { + + return .init( + from: self, + select: .init(selectTerms), + groupBy: .init(), + fetchClauses: [] + ) + } + + public func sectionBy(_ sectionKeyPath: KeyPathString) -> SectionMonitorChainBuilder { + + return self.sectionBy(sectionKeyPath, { $0 }) + } + + public func sectionBy(_ sectionKeyPath: KeyPathString, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder { + + return .init( + from: self, + sectionBy: .init(sectionKeyPath, sectionIndexTransformer), + fetchClauses: [] + ) + } + + public func `where`(_ clause: Where) -> FetchChainBuilder { + + return self.fetchChain(appending: clause) + } + + public func `where`(format: String, _ args: Any...) -> FetchChainBuilder { + + return self.fetchChain(appending: Where(format, argumentArray: args)) + } + + public func `where`(format: String, argumentArray: [Any]?) -> FetchChainBuilder { + + return self.fetchChain(appending: Where(format, argumentArray: argumentArray)) + } + + public func orderBy(_ sortKey: OrderBy.SortKey, _ sortKeys: OrderBy.SortKey...) -> FetchChainBuilder { + + return self.fetchChain(appending: OrderBy([sortKey] + sortKeys)) + } + + public func tweak(_ fetchRequest: @escaping (NSFetchRequest) -> Void) -> FetchChainBuilder { + + return self.fetchChain(appending: Tweak(fetchRequest)) + } + + public func appending(_ clause: FetchClause) -> FetchChainBuilder { + + return self.fetchChain(appending: clause) + } + + + // MARK: Private + + private func fetchChain(appending clause: FetchClause) -> FetchChainBuilder { + + return .init(from: self, fetchClauses: [clause]) + } +} + +public extension FetchChainBuilder { + + public func `where`(_ clause: Where) -> FetchChainBuilder { + + return self.fetchChain(appending: clause) + } + + public func `where`(format: String, _ args: Any...) -> FetchChainBuilder { + + return self.fetchChain(appending: Where(format, argumentArray: args)) + } + + public func `where`(format: String, argumentArray: [Any]?) -> FetchChainBuilder { + + return self.fetchChain(appending: Where(format, argumentArray: argumentArray)) + } + + public func orderBy(_ sortKey: OrderBy.SortKey, _ sortKeys: OrderBy.SortKey...) -> FetchChainBuilder { + + return self.fetchChain(appending: OrderBy([sortKey] + sortKeys)) + } + + public func tweak(_ fetchRequest: @escaping (NSFetchRequest) -> Void) -> FetchChainBuilder { + + return self.fetchChain(appending: Tweak(fetchRequest)) + } + + public func appending(_ clause: FetchClause) -> FetchChainBuilder { + + return self.fetchChain(appending: clause) + } + + + // MARK: Private + + private func fetchChain(appending clause: FetchClause) -> FetchChainBuilder { + + return .init( + from: self.from, + fetchClauses: self.fetchClauses + [clause] + ) + } +} + +public extension QueryChainBuilder { + + public func groupBy(_ keyPath: KeyPathString, _ keyPaths: KeyPathString...) -> QueryChainBuilder { + + return self.groupBy([keyPath] + keyPaths) + } + + public func groupBy(_ keyPaths: [KeyPathString]) -> QueryChainBuilder { + + return .init( + from: self.from, + select: self.select, + groupBy: .init(keyPaths), + fetchClauses: self.fetchClauses + ) + } + + public func `where`(_ clause: Where) -> QueryChainBuilder { + + return self.queryChain(appending: clause) + } + + public func `where`(format: String, _ args: Any...) -> QueryChainBuilder { + + return self.queryChain(appending: Where(format, argumentArray: args)) + } + + public func `where`(format: String, argumentArray: [Any]?) -> QueryChainBuilder { + + return self.queryChain(appending: Where(format, argumentArray: argumentArray)) + } + + public func orderBy(_ sortKey: OrderBy.SortKey, _ sortKeys: OrderBy.SortKey...) -> QueryChainBuilder { + + return self.queryChain(appending: OrderBy([sortKey] + sortKeys)) + } + + public func tweak(_ fetchRequest: @escaping (NSFetchRequest) -> Void) -> QueryChainBuilder { + + return self.queryChain(appending: Tweak(fetchRequest)) + } + + public func appending(_ clause: FetchClause) -> QueryChainBuilder { + + return self.queryChain(appending: clause) + } + + + // MARK: Private + + private func queryChain(appending clause: FetchClause) -> QueryChainBuilder { + + return .init( + from: self.from, + select: self.select, + groupBy: self.groupBy, + fetchClauses: self.fetchClauses + [clause] + ) + } +} + +public extension SectionMonitorChainBuilder { + + public func `where`(_ clause: Where) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: clause) + } + + public func `where`(format: String, _ args: Any...) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: Where(format, argumentArray: args)) + } + + public func `where`(format: String, argumentArray: [Any]?) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: Where(format, argumentArray: argumentArray)) + } + + public func orderBy(_ sortKey: OrderBy.SortKey, _ sortKeys: OrderBy.SortKey...) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: OrderBy([sortKey] + sortKeys)) + } + + public func tweak(_ fetchRequest: @escaping (NSFetchRequest) -> Void) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: Tweak(fetchRequest)) + } + + public func appending(_ clause: FetchClause) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: clause) + } + + + // MARK: Private + + private func sectionMonitorChain(appending clause: FetchClause) -> SectionMonitorChainBuilder { + + return .init( + from: self.from, + sectionBy: self.sectionBy, + fetchClauses: self.fetchClauses + [clause] + ) + } +} diff --git a/Sources/ClauseTypes.swift b/Sources/ClauseTypes.swift index b03f3e2..aa92003 100644 --- a/Sources/ClauseTypes.swift +++ b/Sources/ClauseTypes.swift @@ -43,7 +43,7 @@ public protocol FetchClause { /** The `QueryClause` implement clauses used to configure `NSFetchRequest`s. */ -public protocol QueryClause { +public protocol QueryClause: FetchClause { func applyToFetchRequest(_ fetchRequest: NSFetchRequest) } @@ -54,7 +54,7 @@ public protocol QueryClause { /** The `DeleteClause` implement clauses used to configure `NSFetchRequest`s. */ -public protocol DeleteClause { +public protocol DeleteClause: FetchClause { func applyToFetchRequest(_ fetchRequest: NSFetchRequest) } diff --git a/Sources/CoreStore+Observing.swift b/Sources/CoreStore+Observing.swift index d5e543b..d785255 100644 --- a/Sources/CoreStore+Observing.swift +++ b/Sources/CoreStore+Observing.swift @@ -38,7 +38,7 @@ public extension CoreStore { - parameter object: the `DynamicObject` to observe changes from - returns: a `ObjectMonitor` that monitors changes to `object` */ - public static func monitorObject(_ object: T) -> ObjectMonitor { + public static func monitorObject(_ object: D) -> ObjectMonitor { return self.defaultStack.monitorObject(object) } @@ -50,7 +50,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public static func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { + public static func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { return self.defaultStack.monitorList(from, fetchClauses) } @@ -62,7 +62,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public static func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { + public static func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { return self.defaultStack.monitorList(from, fetchClauses) } @@ -74,7 +74,7 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { + public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } @@ -86,7 +86,7 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { + public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } @@ -99,7 +99,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { + public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) } @@ -112,7 +112,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { + public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) } @@ -125,7 +125,7 @@ public extension CoreStore { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { + public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } @@ -138,7 +138,7 @@ public extension CoreStore { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { + public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } diff --git a/Sources/CoreStore+Querying.swift b/Sources/CoreStore+Querying.swift index 48cf117..3d403ef 100644 --- a/Sources/CoreStore+Querying.swift +++ b/Sources/CoreStore+Querying.swift @@ -37,7 +37,7 @@ public extension CoreStore { - parameter object: a reference to the object created/fetched outside the `DataStack` - returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found. */ - public static func fetchExisting(_ object: T) -> T? { + public static func fetchExisting(_ object: D) -> D? { return self.defaultStack.fetchExisting(object) } @@ -48,7 +48,7 @@ public extension CoreStore { - parameter objectID: the `NSManagedObjectID` for the object - returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found. */ - public static func fetchExisting(_ objectID: NSManagedObjectID) -> T? { + public static func fetchExisting(_ objectID: NSManagedObjectID) -> D? { return self.defaultStack.fetchExisting(objectID) } @@ -59,7 +59,7 @@ public extension CoreStore { - parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack` - returns: the `DynamicObject` array for objects that exists in the `DataStack` */ - public static func fetchExisting(_ objects: S) -> [T] where S.Iterator.Element == T { + public static func fetchExisting(_ objects: S) -> [D] where S.Iterator.Element == D { return self.defaultStack.fetchExisting(objects) } @@ -70,7 +70,7 @@ public extension CoreStore { - parameter objectIDs: the `NSManagedObjectID` array for the objects - returns: the `DynamicObject` array for objects that exists in the `DataStack` */ - public static func fetchExisting(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { + public static func fetchExisting(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID { return self.defaultStack.fetchExisting(objectIDs) } @@ -82,7 +82,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public static func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { + public static func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> D? { return self.defaultStack.fetchOne(from, fetchClauses) } @@ -94,7 +94,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public static func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { + public static func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> D? { return self.defaultStack.fetchOne(from, fetchClauses) } @@ -106,7 +106,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public static func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { + public static func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [D]? { return self.defaultStack.fetchAll(from, fetchClauses) } @@ -118,7 +118,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public static func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { + public static func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [D]? { return self.defaultStack.fetchAll(from, fetchClauses) } @@ -130,7 +130,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public static func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public static func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { return self.defaultStack.fetchCount(from, fetchClauses) } @@ -142,7 +142,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public static func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public static func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { return self.defaultStack.fetchCount(from, fetchClauses) } @@ -154,7 +154,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public static func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public static func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { return self.defaultStack.fetchObjectID(from, fetchClauses) } @@ -166,7 +166,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public static func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public static func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { return self.defaultStack.fetchObjectID(from, fetchClauses) } @@ -178,7 +178,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public static func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public static func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { return self.defaultStack.fetchObjectIDs(from, fetchClauses) } @@ -190,7 +190,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public static func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public static func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { return self.defaultStack.fetchObjectIDs(from, fetchClauses) } @@ -205,7 +205,7 @@ public extension CoreStore { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { return self.defaultStack.queryValue(from, selectClause, queryClauses) } @@ -220,7 +220,7 @@ public extension CoreStore { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { + public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { return self.defaultStack.queryValue(from, selectClause, queryClauses) } @@ -235,7 +235,7 @@ public extension CoreStore { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { return self.defaultStack.queryAttributes(from, selectClause, queryClauses) } @@ -250,7 +250,7 @@ public extension CoreStore { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { + public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { return self.defaultStack.queryAttributes(from, selectClause, queryClauses) } diff --git a/Sources/CoreStoreFetchedResultsController.swift b/Sources/CoreStoreFetchedResultsController.swift index 6fe2cf3..b0c18cb 100644 --- a/Sources/CoreStoreFetchedResultsController.swift +++ b/Sources/CoreStoreFetchedResultsController.swift @@ -35,7 +35,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll // MARK: Internal @nonobjc - internal convenience init(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { + internal convenience init(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { self.init( context: dataStack.mainContext, @@ -47,7 +47,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll } @nonobjc - internal init(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { + internal init(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { _ = from.applyToFetchRequest( fetchRequest, diff --git a/Sources/CoreStoreObject+Querying.swift b/Sources/CoreStoreObject+Querying.swift index 0a87043..5f8c1ef 100644 --- a/Sources/CoreStoreObject+Querying.swift +++ b/Sources/CoreStoreObject+Querying.swift @@ -26,6 +26,58 @@ import CoreData import Foundation +//public extension From where D: NSManagedObject { +// +//// public func select(_ resultType: R.Type, _ selectTerm: SelectTerm, _ selectTerms: SelectTerm...) -> QueryChainBuilder { +//// +//// return self.select(resultType, [selectTerm] + selectTerms) +//// } +//// +//// public func select(_ resultType: R.Type, _ selectTerms: [SelectTerm]) -> QueryChainBuilder { +//// +//// return .init( +//// from: self, +//// select: .init(selectTerms), +//// groupBy: .init(), +//// fetchClauses: [] +//// ) +//// } +// +// public func sectionBy(_ sectionKeyPath: KeyPath) -> SectionMonitorChainBuilder { +// +// return self.sectionBy(sectionKeyPath._kvcKeyPathString!, { $0 }) +// } +// +// public func sectionBy(_ sectionKeyPath: KeyPath, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder { +// +// return self.sectionBy(sectionKeyPath._kvcKeyPathString!, sectionIndexTransformer) +// } +// +// public func `where`(_ keyPath: KeyPath, isEqualTo value: Void?) -> FetchChainBuilder { +// +// return self.where(keyPath._kvcKeyPathString!, isEqualTo: value) +// } +// +// public func `where`(_ keyPath: KeyPath, isEqualTo value: U?) -> FetchChainBuilder { +// +// return self.where(keyPath._kvcKeyPathString!, isEqualTo: value) +// } +// +// public func `where`(_ keyPath: KeyPath, isEqualTo object: D?) -> FetchChainBuilder { +// +// return self.where(keyPath._kvcKeyPathString!, isEqualTo: object) +// } +// +// public func `where`(_ keyPath: KeyPath, isMemberOf list: S) -> FetchChainBuilder where S.Iterator.Element: QueryableAttributeType { +// +// return self.where(keyPath._kvcKeyPathString!, isMemberOf: list) +// } +// +// public func `where`(_ keyPath: KeyPath, isMemberOf list: S) -> FetchChainBuilder where S.Iterator.Element == D { +// +// return self.where(keyPath._kvcKeyPathString!, isMemberOf: list) +// } +//} // MARK: - DynamicObject @@ -92,7 +144,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchOne(From(), Person.where { $0.nickname == "John" }) ``` */ - public static func `where`(_ condition: (Self) -> Where) -> Where { + public static func `where`(_ condition: (Self) -> Where) -> Where { return condition(self.meta) } @@ -103,7 +155,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchAll(From(), Person.orderBy(ascending: { $0.age })) ``` */ - public static func orderBy(ascending attribute: (Self) -> ValueContainer.Required) -> OrderBy { + public static func orderBy(ascending attribute: (Self) -> ValueContainer.Required) -> OrderBy { return OrderBy(.ascending(attribute(self.meta).keyPath)) } @@ -114,7 +166,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchAll(From(), Person.orderBy(ascending: { $0.age })) ``` */ - public static func orderBy(ascending attribute: (Self) -> ValueContainer.Optional) -> OrderBy { + public static func orderBy(ascending attribute: (Self) -> ValueContainer.Optional) -> OrderBy { return OrderBy(.ascending(attribute(self.meta).keyPath)) } @@ -125,7 +177,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchAll(From(), Person.orderBy(descending: { $0.age })) ``` */ - public static func orderBy(descending attribute: (Self) -> ValueContainer.Required) -> OrderBy { + public static func orderBy(descending attribute: (Self) -> ValueContainer.Required) -> OrderBy { return OrderBy(.descending(attribute(self.meta).keyPath)) } @@ -136,22 +188,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchAll(From(), Person.orderBy(descending: { $0.age })) ``` */ - public static func orderBy(descending attribute: (Self) -> ValueContainer.Optional) -> OrderBy { - - return OrderBy(.descending(attribute(self.meta).keyPath)) - } - - - // MARK: Deprecated - - @available(*, deprecated, renamed: "orderBy(ascending:)") - public static func ascending(_ attribute: (Self) -> ValueContainer.Optional) -> OrderBy { - - return OrderBy(.ascending(attribute(self.meta).keyPath)) - } - - @available(*, deprecated, renamed: "orderBy(descending:)") - public static func descending(_ attribute: (Self) -> ValueContainer.Optional) -> OrderBy { + public static func orderBy(descending attribute: (Self) -> ValueContainer.Optional) -> OrderBy { return OrderBy(.descending(attribute(self.meta).keyPath)) } @@ -169,7 +206,7 @@ public extension ValueContainer.Required { ``` */ @inline(__always) - public static func == (_ attribute: ValueContainer.Required, _ value: V) -> Where { + public static func == (_ attribute: ValueContainer.Required, _ value: V) -> Where { return Where(attribute.keyPath, isEqualTo: value) } @@ -181,7 +218,7 @@ public extension ValueContainer.Required { ``` */ @inline(__always) - public static func != (_ attribute: ValueContainer.Required, _ value: V) -> Where { + public static func != (_ attribute: ValueContainer.Required, _ value: V) -> Where { return !Where(attribute.keyPath, isEqualTo: value) } @@ -193,7 +230,7 @@ public extension ValueContainer.Required { ``` */ @inline(__always) - public static func < (_ attribute: ValueContainer.Required, _ value: V) -> Where { + public static func < (_ attribute: ValueContainer.Required, _ value: V) -> Where { return Where("%K < %@", attribute.keyPath, value) } @@ -205,7 +242,7 @@ public extension ValueContainer.Required { ``` */ @inline(__always) - public static func > (_ attribute: ValueContainer.Required, _ value: V) -> Where { + public static func > (_ attribute: ValueContainer.Required, _ value: V) -> Where { return Where("%K > %@", attribute.keyPath, value) } @@ -217,7 +254,7 @@ public extension ValueContainer.Required { ``` */ @inline(__always) - public static func <= (_ attribute: ValueContainer.Required, _ value: V) -> Where { + public static func <= (_ attribute: ValueContainer.Required, _ value: V) -> Where { return Where("%K <= %@", attribute.keyPath, value) } @@ -229,7 +266,7 @@ public extension ValueContainer.Required { ``` */ @inline(__always) - public static func >= (_ attribute: ValueContainer.Required, _ value: V) -> Where { + public static func >= (_ attribute: ValueContainer.Required, _ value: V) -> Where { return Where("%K >= %@", attribute.keyPath, value) } @@ -241,7 +278,7 @@ public extension ValueContainer.Required { ``` */ @inline(__always) - public static func ~= (_ sequence: S, _ attribute: ValueContainer.Required) -> Where where S.Iterator.Element == V { + public static func ~= (_ sequence: S, _ attribute: ValueContainer.Required) -> Where where S.Iterator.Element == V { return Where(attribute.keyPath, isMemberOf: sequence) } @@ -259,7 +296,7 @@ public extension ValueContainer.Optional { ``` */ @inline(__always) - public static func == (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + public static func == (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { return Where(attribute.keyPath, isEqualTo: value) } @@ -271,7 +308,7 @@ public extension ValueContainer.Optional { ``` */ @inline(__always) - public static func != (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + public static func != (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { return !Where(attribute.keyPath, isEqualTo: value) } @@ -283,7 +320,7 @@ public extension ValueContainer.Optional { ``` */ @inline(__always) - public static func < (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + public static func < (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { if let value = value { @@ -302,7 +339,7 @@ public extension ValueContainer.Optional { ``` */ @inline(__always) - public static func > (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + public static func > (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { if let value = value { @@ -321,7 +358,7 @@ public extension ValueContainer.Optional { ``` */ @inline(__always) - public static func <= (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + public static func <= (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { if let value = value { @@ -340,7 +377,7 @@ public extension ValueContainer.Optional { ``` */ @inline(__always) - public static func >= (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + public static func >= (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { if let value = value { @@ -359,7 +396,7 @@ public extension ValueContainer.Optional { ``` */ @inline(__always) - public static func ~= (_ sequence: S, _ attribute: ValueContainer.Optional) -> Where where S.Iterator.Element == V { + public static func ~= (_ sequence: S, _ attribute: ValueContainer.Optional) -> Where where S.Iterator.Element == V { return Where(attribute.keyPath, isMemberOf: sequence) } @@ -377,7 +414,7 @@ public extension RelationshipContainer.ToOne { ``` */ @inline(__always) - public static func == (_ relationship: RelationshipContainer.ToOne, _ object: D?) -> Where { + public static func == (_ relationship: RelationshipContainer.ToOne, _ object: D?) -> Where { return Where(relationship.keyPath, isEqualTo: object) } @@ -389,7 +426,7 @@ public extension RelationshipContainer.ToOne { ``` */ @inline(__always) - public static func != (_ relationship: RelationshipContainer.ToOne, _ object: D?) -> Where { + public static func != (_ relationship: RelationshipContainer.ToOne, _ object: D?) -> Where { return !Where(relationship.keyPath, isEqualTo: object) } @@ -401,7 +438,7 @@ public extension RelationshipContainer.ToOne { ``` */ @inline(__always) - public static func ~= (_ relationship: RelationshipContainer.ToOne, _ object: D?) -> Where { + public static func ~= (_ relationship: RelationshipContainer.ToOne, _ object: D?) -> Where { return Where(relationship.keyPath, isEqualTo: object) } @@ -413,7 +450,7 @@ public extension RelationshipContainer.ToOne { ``` */ @inline(__always) - public static func ~= (_ sequence: S, _ relationship: RelationshipContainer.ToOne) -> Where where S.Iterator.Element == D { + public static func ~= (_ sequence: S, _ relationship: RelationshipContainer.ToOne) -> Where where S.Iterator.Element == D { return Where(relationship.keyPath, isMemberOf: sequence) } diff --git a/Sources/DataStack+Observing.swift b/Sources/DataStack+Observing.swift index e4dea00..7777e82 100644 --- a/Sources/DataStack+Observing.swift +++ b/Sources/DataStack+Observing.swift @@ -38,7 +38,7 @@ public extension DataStack { - parameter object: the `DynamicObject` to observe changes from - returns: a `ObjectMonitor` that monitors changes to `object` */ - public func monitorObject(_ object: T) -> ObjectMonitor { + public func monitorObject(_ object: D) -> ObjectMonitor { CoreStore.assert( Thread.isMainThread, @@ -54,7 +54,7 @@ public extension DataStack { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { + public func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { return self.monitorList(from, fetchClauses) } @@ -66,7 +66,7 @@ public extension DataStack { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { + public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { CoreStore.assert( Thread.isMainThread, @@ -82,7 +82,7 @@ public extension DataStack { CoreStore.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." ) } ) @@ -95,7 +95,7 @@ public extension DataStack { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } @@ -107,7 +107,7 @@ public extension DataStack { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { CoreStore.assert( Thread.isMainThread, @@ -123,7 +123,7 @@ public extension DataStack { CoreStore.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." ) }, createAsynchronously: createAsynchronously @@ -138,7 +138,7 @@ public extension DataStack { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { + public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { return self.monitorSectionedList(from, sectionBy, fetchClauses) } @@ -151,7 +151,7 @@ public extension DataStack { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { + public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { CoreStore.assert( Thread.isMainThread, @@ -168,7 +168,7 @@ public extension DataStack { CoreStore.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." ) } ) @@ -182,7 +182,7 @@ public extension DataStack { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } @@ -195,7 +195,7 @@ public extension DataStack { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { CoreStore.assert( Thread.isMainThread, @@ -212,7 +212,7 @@ public extension DataStack { CoreStore.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." ) }, createAsynchronously: createAsynchronously diff --git a/Sources/DataStack+Querying.swift b/Sources/DataStack+Querying.swift index e87b40d..e600784 100644 --- a/Sources/DataStack+Querying.swift +++ b/Sources/DataStack+Querying.swift @@ -39,7 +39,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter object: a reference to the object created/fetched outside the `DataStack` - returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found. */ - public func fetchExisting(_ object: T) -> T? { + public func fetchExisting(_ object: D) -> D? { return self.mainContext.fetchExisting(object) } @@ -50,7 +50,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter objectID: the `NSManagedObjectID` for the object - returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found. */ - public func fetchExisting(_ objectID: NSManagedObjectID) -> T? { + public func fetchExisting(_ objectID: NSManagedObjectID) -> D? { return self.mainContext.fetchExisting(objectID) } @@ -61,7 +61,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack` - returns: the `DynamicObject` array for objects that exists in the `DataStack` */ - public func fetchExisting(_ objects: S) -> [T] where S.Iterator.Element == T { + public func fetchExisting(_ objects: S) -> [D] where S.Iterator.Element == D { return self.mainContext.fetchExisting(objects) } @@ -72,7 +72,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter objectIDs: the `NSManagedObjectID` array for the objects - returns: the `DynamicObject` array for objects that exists in the `DataStack` */ - public func fetchExisting(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { + public func fetchExisting(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID { return self.mainContext.fetchExisting(objectIDs) } @@ -84,7 +84,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> D? { CoreStore.assert( Thread.isMainThread, @@ -100,7 +100,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> D? { CoreStore.assert( Thread.isMainThread, @@ -109,6 +109,16 @@ extension DataStack: FetchableSource, QueryableSource { return self.mainContext.fetchOne(from, fetchClauses) } + // TODO: docs + public func fetchOne(_ clauseChain: B) -> B.ObjectType? { + + CoreStore.assert( + Thread.isMainThread, + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + ) + return self.mainContext.fetchOne(clauseChain) + } + /** Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -116,7 +126,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [D]? { CoreStore.assert( Thread.isMainThread, @@ -132,7 +142,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [D]? { CoreStore.assert( Thread.isMainThread, @@ -141,6 +151,16 @@ extension DataStack: FetchableSource, QueryableSource { return self.mainContext.fetchAll(from, fetchClauses) } + // TODO: docs + public func fetchAll(_ clauseChain: B) -> [B.ObjectType]? { + + CoreStore.assert( + Thread.isMainThread, + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + ) + return self.mainContext.fetchAll(clauseChain) + } + /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -148,7 +168,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { CoreStore.assert( Thread.isMainThread, @@ -164,7 +184,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { CoreStore.assert( Thread.isMainThread, @@ -173,6 +193,16 @@ extension DataStack: FetchableSource, QueryableSource { return self.mainContext.fetchCount(from, fetchClauses) } + // TODO: docs + public func fetchCount(_ clauseChain: B) -> Int? { + + CoreStore.assert( + Thread.isMainThread, + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + ) + return self.mainContext.fetchCount(clauseChain) + } + /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -180,7 +210,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { CoreStore.assert( Thread.isMainThread, @@ -196,7 +226,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { CoreStore.assert( Thread.isMainThread, @@ -205,6 +235,16 @@ extension DataStack: FetchableSource, QueryableSource { return self.mainContext.fetchObjectID(from, fetchClauses) } + // TODO: docs + public func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { + + CoreStore.assert( + Thread.isMainThread, + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + ) + return self.mainContext.fetchObjectID(clauseChain) + } + /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -212,7 +252,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { CoreStore.assert( Thread.isMainThread, @@ -228,7 +268,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { CoreStore.assert( Thread.isMainThread, @@ -237,6 +277,16 @@ extension DataStack: FetchableSource, QueryableSource { return self.mainContext.fetchObjectIDs(from, fetchClauses) } + // TODO: docs + public func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { + + CoreStore.assert( + Thread.isMainThread, + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + ) + return self.mainContext.fetchObjectIDs(clauseChain) + } + // MARK: QueryableSource @@ -250,7 +300,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { CoreStore.assert( Thread.isMainThread, @@ -269,7 +319,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { CoreStore.assert( Thread.isMainThread, @@ -288,7 +338,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { CoreStore.assert( Thread.isMainThread, @@ -307,7 +357,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { CoreStore.assert( Thread.isMainThread, diff --git a/Sources/DynamicObject.swift b/Sources/DynamicObject.swift index c48bdba..664d013 100644 --- a/Sources/DynamicObject.swift +++ b/Sources/DynamicObject.swift @@ -79,9 +79,9 @@ extension NSManagedObject: DynamicObject { public class func cs_fromRaw(object: NSManagedObject) -> Self { @inline(__always) - func forceCast(_ value: Any) -> T { + func forceCast(_ value: Any) -> D { - return value as! T + return value as! D } return forceCast(object) } @@ -125,9 +125,9 @@ extension CoreStoreObject { if let coreStoreObject = object.coreStoreObject { @inline(__always) - func forceCast(_ value: CoreStoreObject) -> T { + func forceCast(_ value: CoreStoreObject) -> D { - return value as! T + return value as! D } return forceCast(coreStoreObject) } diff --git a/Sources/FetchCondition.swift b/Sources/FetchCondition.swift deleted file mode 100644 index ac05514..0000000 --- a/Sources/FetchCondition.swift +++ /dev/null @@ -1,143 +0,0 @@ -// -// FetchCondition.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 - -public struct ChainedClauseBuilder { - - public let from: From - public let fetchClauses: [FetchClause] = [] - - internal init(from: From) { - - self.from = from - } -} - -extension From: ClauseChain { - - public typealias ObjectType = T - public typealias TraitType = FetchTrait - - public var builder: ChainedClauseBuilder { - - return .init(from: self) - } -} - -public struct ChainedWhere: ClauseChain { - - public typealias ObjectType = D - public typealias TraitType = T - - public let builder: ChainedClauseBuilder - - fileprivate init(builder: ChainedClauseBuilder) { - - var newBuilder = builder -// newBuilder.fetchClauses.append(Where()) - self.builder = newBuilder - } -} - -public struct ChainedOrderBy: ClauseChain { - - public typealias ObjectType = D - public typealias TraitType = T - - public let builder: ChainedClauseBuilder - - fileprivate init(builder: ChainedClauseBuilder) { - - var newBuilder = builder -// newBuilder.fetchClauses.append(Where()) - self.builder = newBuilder - } -} - -public struct ChainedSelect: ClauseChain { - - public typealias ObjectType = D - public typealias TraitType = T - - public let builder: ChainedClauseBuilder - - fileprivate init(builder: ChainedClauseBuilder) { - - var newBuilder = builder -// newBuilder.fetchClauses.append(Where()) - self.builder = newBuilder - } -} - - - - - -public protocol ClauseTrait {} -public enum FetchTrait: ClauseTrait {} -public enum QueryTrait: ClauseTrait {} -public enum SectionTrait: ClauseTrait {} - - -public protocol ClauseChain { - - associatedtype ObjectType: DynamicObject - associatedtype TraitType: ClauseTrait - - var builder: ChainedClauseBuilder { get } -} - -public extension ClauseChain where Self.TraitType == FetchTrait { - - public func `where`() -> ChainedWhere { - - return .init(builder: self.builder) - } - - public func orderBy() -> ChainedOrderBy { - - return .init(builder: self.builder) - } - - public func select() -> ChainedSelect { - - return .init(builder: self.builder) - } -} - -public extension ClauseChain where Self.TraitType == QueryTrait { - - public func `where`() -> ChainedWhere { - - return .init(builder: self.builder) - } - - public func orderBy() -> ChainedOrderBy { - - return .init(builder: self.builder) - } -} diff --git a/Sources/FetchableSource.swift b/Sources/FetchableSource.swift index 12f677a..ce63ef3 100644 --- a/Sources/FetchableSource.swift +++ b/Sources/FetchableSource.swift @@ -40,7 +40,7 @@ public protocol FetchableSource: class { - parameter object: a reference to the object created/fetched outside the `FetchableSource`'s context - returns: the `DynamicObject` instance if the object exists in the `FetchableSource`'s context, or `nil` if not found. */ - func fetchExisting(_ object: T) -> T? + func fetchExisting(_ object: D) -> D? /** Fetches the `DynamicObject` instance in the `FetchableSource`'s context from an `NSManagedObjectID`. @@ -48,7 +48,7 @@ public protocol FetchableSource: class { - parameter objectID: the `NSManagedObjectID` for the object - returns: the `DynamicObject` instance if the object exists in the `FetchableSource`, or `nil` if not found. */ - func fetchExisting(_ objectID: NSManagedObjectID) -> T? + func fetchExisting(_ objectID: NSManagedObjectID) -> D? /** Fetches the `DynamicObject` instances in the `FetchableSource`'s context from references created from another managed object context. @@ -56,7 +56,7 @@ public protocol FetchableSource: class { - parameter objects: an array of `DynamicObject`s created/fetched outside the `FetchableSource`'s context - returns: the `DynamicObject` array for objects that exists in the `FetchableSource` */ - func fetchExisting(_ objects: S) -> [T] where S.Iterator.Element == T + func fetchExisting(_ objects: S) -> [D] where S.Iterator.Element == D /** Fetches the `DynamicObject` instances in the `FetchableSource`'s context from a list of `NSManagedObjectID`. @@ -64,7 +64,7 @@ public protocol FetchableSource: class { - parameter objectIDs: the `NSManagedObjectID` array for the objects - returns: the `DynamicObject` array for objects that exists in the `FetchableSource`'s context */ - func fetchExisting(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID + func fetchExisting(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID /** Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -73,7 +73,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? + func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> D? /** Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -82,7 +82,10 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? + func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> D? + + // TODO: docs + func fetchOne(_ clauseChain: B) -> B.ObjectType? /** Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -91,7 +94,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? + func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [D]? /** Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -100,7 +103,10 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? + func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [D]? + + // TODO: docs + func fetchAll(_ clauseChain: B) -> [B.ObjectType]? /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -109,7 +115,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? + func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -118,7 +124,10 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? + func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? + + // TODO: docs + func fetchCount(_ clauseChain: B) -> Int? /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -127,7 +136,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? + func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -136,7 +145,10 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? + func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? + + // TODO: docs + func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -145,7 +157,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? + func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -154,7 +166,10 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? + func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? + + // TODO: docs + func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? /** The internal `NSManagedObjectContext` managed by this `FetchableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases. diff --git a/Sources/From.swift b/Sources/From.swift index 6a746fa..67ec6fe 100644 --- a/Sources/From.swift +++ b/Sources/From.swift @@ -39,12 +39,12 @@ import CoreData let person = transaction.fetchOne(From("Configuration1")) ``` */ -public struct From { +public struct From { /** The associated `NSManagedObject` or `CoreStoreObject` entity class */ - public let entityClass: T.Type + public let entityClass: D.Type /** The `NSPersistentStore` configuration names to associate objects from. @@ -60,7 +60,7 @@ public struct From { */ public init() { - self.init(entityClass: T.self, configurations: nil) + self.init(entityClass: D.self, configurations: nil) } /** @@ -70,7 +70,7 @@ public struct From { ``` - parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type */ - public init(_ entity: T.Type) { + public init(_ entity: D.Type) { self.init(entityClass: entity, configurations: nil) } @@ -85,7 +85,7 @@ public struct From { */ public init(_ configuration: ModelConfiguration, _ otherConfigurations: ModelConfiguration...) { - self.init(entityClass: T.self, configurations: [configuration] + otherConfigurations) + self.init(entityClass: D.self, configurations: [configuration] + otherConfigurations) } /** @@ -97,7 +97,7 @@ public struct From { */ public init(_ configurations: [ModelConfiguration]) { - self.init(entityClass: T.self, configurations: configurations) + self.init(entityClass: D.self, configurations: configurations) } /** @@ -109,7 +109,7 @@ public struct From { - parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration. - parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter) */ - public init(_ entity: T.Type, _ configuration: ModelConfiguration, _ otherConfigurations: ModelConfiguration...) { + public init(_ entity: D.Type, _ configuration: ModelConfiguration, _ otherConfigurations: ModelConfiguration...) { self.init(entityClass: entity, configurations: [configuration] + otherConfigurations) } @@ -122,7 +122,7 @@ public struct From { - parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type - parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject` or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration. */ - public init(_ entity: T.Type, _ configurations: [ModelConfiguration]) { + public init(_ entity: D.Type, _ configurations: [ModelConfiguration]) { self.init(entityClass: entity, configurations: configurations) } @@ -132,7 +132,7 @@ public struct From { internal let findPersistentStores: (_ context: NSManagedObjectContext) -> [NSPersistentStore]? - internal init(entityClass: T.Type, configurations: [ModelConfiguration]?, findPersistentStores: @escaping (_ context: NSManagedObjectContext) -> [NSPersistentStore]?) { + internal init(entityClass: D.Type, configurations: [ModelConfiguration]?, findPersistentStores: @escaping (_ context: NSManagedObjectContext) -> [NSPersistentStore]?) { self.entityClass = entityClass self.configurations = configurations @@ -167,7 +167,7 @@ public struct From { // MARK: Private - private init(entityClass: T.Type, configurations: [ModelConfiguration]?) { + private init(entityClass: D.Type, configurations: [ModelConfiguration]?) { self.entityClass = entityClass self.configurations = configurations diff --git a/Sources/Into.swift b/Sources/Into.swift index 8730af9..f016a05 100644 --- a/Sources/Into.swift +++ b/Sources/Into.swift @@ -39,12 +39,12 @@ import CoreData let person = transaction.create(Into("Configuration1")) ``` */ -public struct Into: Hashable { +public struct Into: Hashable { /** The associated `NSManagedObject` or `CoreStoreObject` entity class */ - public let entityClass: T.Type + public let entityClass: D.Type /** The `NSPersistentStore` configuration name to associate objects from. @@ -60,7 +60,7 @@ public struct Into: Hashable { */ public init() { - self.init(entityClass: T.self, configuration: nil, inferStoreIfPossible: true) + self.init(entityClass: D.self, configuration: nil, inferStoreIfPossible: true) } /** @@ -70,7 +70,7 @@ public struct Into: Hashable { ``` - parameter entity: the `NSManagedObject` type to be created */ - public init(_ entity: T.Type) { + public init(_ entity: D.Type) { self.init(entityClass: entity, configuration: nil, inferStoreIfPossible: true) } @@ -84,7 +84,7 @@ public struct Into: Hashable { */ public init(_ configuration: ModelConfiguration) { - self.init(entityClass: T.self, configuration: configuration, inferStoreIfPossible: false) + self.init(entityClass: D.self, configuration: configuration, inferStoreIfPossible: false) } /** @@ -95,7 +95,7 @@ public struct Into: Hashable { - parameter entity: the `NSManagedObject` type to be created - parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration. */ - public init(_ entity: T.Type, _ configuration: ModelConfiguration) { + public init(_ entity: D.Type, _ configuration: ModelConfiguration) { self.init(entityClass: entity, configuration: configuration, inferStoreIfPossible: false) } @@ -125,7 +125,7 @@ public struct Into: Hashable { internal let inferStoreIfPossible: Bool - internal init(entityClass: T.Type, configuration: ModelConfiguration, inferStoreIfPossible: Bool) { + internal init(entityClass: D.Type, configuration: ModelConfiguration, inferStoreIfPossible: Bool) { self.entityClass = entityClass self.configuration = configuration diff --git a/Sources/NSFetchedResultsController+Convenience.swift b/Sources/NSFetchedResultsController+Convenience.swift index d4d7252..3d1c552 100644 --- a/Sources/NSFetchedResultsController+Convenience.swift +++ b/Sources/NSFetchedResultsController+Convenience.swift @@ -42,7 +42,7 @@ public extension DataStack { - returns: an `NSFetchedResultsController` that observes the `DataStack` */ @nonobjc - public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { + public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { return createFRC( fromContext: self.mainContext, @@ -62,7 +62,7 @@ public extension DataStack { - returns: an `NSFetchedResultsController` that observes the `DataStack` */ @nonobjc - public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { + public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { return createFRC( fromContext: self.mainContext, @@ -81,7 +81,7 @@ public extension DataStack { - returns: an `NSFetchedResultsController` that observes the `DataStack` */ @nonobjc - public func createFetchedResultsController(_ from: From, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { + public func createFetchedResultsController(_ from: From, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { return createFRC( fromContext: self.mainContext, @@ -100,7 +100,7 @@ public extension DataStack { - returns: an `NSFetchedResultsController` that observes the `DataStack` */ @nonobjc - public func createFetchedResultsController(forDataStack dataStack: DataStack, _ from: From, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { + public func createFetchedResultsController(forDataStack dataStack: DataStack, _ from: From, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { return createFRC( fromContext: self.mainContext, @@ -127,7 +127,7 @@ public extension UnsafeDataTransaction { - returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction` */ @nonobjc - public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { + public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { return createFRC( fromContext: self.context, @@ -147,7 +147,7 @@ public extension UnsafeDataTransaction { - returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction` */ @nonobjc - public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { + public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { return createFRC( fromContext: self.context, @@ -166,7 +166,7 @@ public extension UnsafeDataTransaction { - returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction` */ @nonobjc - public func createFetchedResultsController(_ from: From, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { + public func createFetchedResultsController(_ from: From, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { return createFRC( fromContext: self.context, @@ -185,7 +185,7 @@ public extension UnsafeDataTransaction { - returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction` */ @nonobjc - public func createFetchedResultsController(_ from: From, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { + public func createFetchedResultsController(_ from: From, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { return createFRC( fromContext: self.context, @@ -201,7 +201,7 @@ public extension UnsafeDataTransaction { // MARK: - Private @available(OSX 10.12, *) -fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: From, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController { +fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: From, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController { let controller = CoreStoreFetchedResultsController( context: context, @@ -214,7 +214,7 @@ fileprivate func createFRC(fromContext context: NSManagedObj CoreStore.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(NSFetchedResultsController.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(cs_typeName(NSFetchedResultsController.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." ) } ) diff --git a/Sources/NSManagedObjectContext+Querying.swift b/Sources/NSManagedObjectContext+Querying.swift index 11e58e6..c9a2d31 100644 --- a/Sources/NSManagedObjectContext+Querying.swift +++ b/Sources/NSManagedObjectContext+Querying.swift @@ -34,7 +34,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { // MARK: FetchableSource @nonobjc - public func fetchExisting(_ object: T) -> T? { + public func fetchExisting(_ object: D) -> D? { let rawObject = object.cs_toRaw() if rawObject.objectID.isTemporaryID { @@ -62,7 +62,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { return object } - return T.cs_fromRaw(object: existingRawObject) + return D.cs_fromRaw(object: existingRawObject) } catch { @@ -75,12 +75,12 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchExisting(_ objectID: NSManagedObjectID) -> T? { + public func fetchExisting(_ objectID: NSManagedObjectID) -> D? { do { let existingObject = try self.existingObject(with: objectID) - return T.cs_fromRaw(object: existingObject) + return D.cs_fromRaw(object: existingObject) } catch _ { @@ -89,25 +89,25 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchExisting(_ objects: S) -> [T] where S.Iterator.Element == T { + public func fetchExisting(_ objects: S) -> [D] where S.Iterator.Element == D { return objects.flatMap({ self.fetchExisting($0.cs_id()) }) } @nonobjc - public func fetchExisting(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { + public func fetchExisting(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID { return objectIDs.flatMap({ self.fetchExisting($0) }) } @nonobjc - public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> D? { return self.fetchOne(from, fetchClauses) } @nonobjc - public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> D? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -123,14 +123,21 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { return self.fetchOne(fetchRequest.dynamicCast()).flatMap(from.entityClass.cs_fromRaw) } + // TODO: docs @nonobjc - public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { + public func fetchOne(_ clauseChain: B) -> B.ObjectType? { + + return self.fetchOne(clauseChain.from, clauseChain.fetchClauses) + } + + @nonobjc + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [D]? { return self.fetchAll(from, fetchClauses) } @nonobjc - public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [D]? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -147,14 +154,21 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { return self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw) } + // TODO: docs @nonobjc - public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public func fetchAll(_ clauseChain: B) -> [B.ObjectType]? { + + return self.fetchAll(clauseChain.from, clauseChain.fetchClauses) + } + + @nonobjc + public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { return self.fetchCount(from, fetchClauses) } @nonobjc - public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -167,14 +181,21 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { return self.fetchCount(fetchRequest.dynamicCast()) } + // TODO: docs @nonobjc - public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public func fetchCount(_ clauseChain: B) -> Int? { + + return self.fetchCount(clauseChain.from, clauseChain.fetchClauses) + } + + @nonobjc + public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { return self.fetchObjectID(from, fetchClauses) } @nonobjc - public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -190,14 +211,21 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { return self.fetchObjectID(fetchRequest.dynamicCast()) } + // TODO: docs @nonobjc - public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { + + return self.fetchObjectID(clauseChain.from, clauseChain.fetchClauses) + } + + @nonobjc + public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { return self.fetchObjectIDs(from, fetchClauses) } @nonobjc - public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -213,6 +241,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { return self.fetchObjectIDs(fetchRequest.dynamicCast()) } + // TODO: docs + @nonobjc + public func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { + + return self.fetchObjectIDs(clauseChain.from, clauseChain.fetchClauses) + } + @nonobjc internal func fetchObjectIDs(_ fetchRequest: NSFetchRequest) -> [NSManagedObjectID]? { @@ -244,13 +279,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { // MARK: QueryableSource @nonobjc - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { return self.queryValue(from, selectClause, queryClauses) } @nonobjc - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -269,13 +304,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { return self.queryAttributes(from, selectClause, queryClauses) } @nonobjc - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -305,13 +340,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { // MARK: Deleting @nonobjc - internal func deleteAll(_ from: From, _ deleteClauses: DeleteClause...) -> Int? { - - return self.deleteAll(from, deleteClauses) - } - - @nonobjc - internal func deleteAll(_ from: From, _ deleteClauses: [DeleteClause]) -> Int? { + internal func deleteAll(_ from: From, _ deleteClauses: [FetchClause]) -> Int? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -347,9 +376,9 @@ internal extension NSManagedObjectContext { // MARK: Fetching @nonobjc - internal func fetchOne(_ fetchRequest: NSFetchRequest) -> T? { + internal func fetchOne(_ fetchRequest: NSFetchRequest) -> D? { - var fetchResults: [T]? + var fetchResults: [D]? var fetchError: Error? self.performAndWait { @@ -374,9 +403,9 @@ internal extension NSManagedObjectContext { } @nonobjc - internal func fetchAll(_ fetchRequest: NSFetchRequest) -> [T]? { + internal func fetchAll(_ fetchRequest: NSFetchRequest) -> [D]? { - var fetchResults: [T]? + var fetchResults: [D]? var fetchError: Error? self.performAndWait { @@ -555,7 +584,7 @@ internal extension NSManagedObjectContext { // MARK: Deleting @nonobjc - internal func deleteAll(_ fetchRequest: NSFetchRequest) -> Int? { + internal func deleteAll(_ fetchRequest: NSFetchRequest) -> Int? { var numberOfDeletedObjects: Int? var fetchError: Error? diff --git a/Sources/ObjectMonitor.swift b/Sources/ObjectMonitor.swift index b2d8db1..79102c7 100644 --- a/Sources/ObjectMonitor.swift +++ b/Sources/ObjectMonitor.swift @@ -273,7 +273,7 @@ public final class ObjectMonitor: Equatable { context: context, fetchRequest: fetchRequest.dynamicCast(), from: From([objectID.persistentStore?.configurationName]), - applyFetchClauses: Where("SELF", isEqualTo: objectID).applyToFetchRequest + applyFetchClauses: Where("SELF", isEqualTo: objectID).applyToFetchRequest ) let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate() diff --git a/Sources/OrderBy.swift b/Sources/OrderBy.swift index 71f5e3e..33611e7 100644 --- a/Sources/OrderBy.swift +++ b/Sources/OrderBy.swift @@ -32,31 +32,12 @@ import CoreData public typealias KeyPathString = String -// MARK: - SortKey - -/** - The `SortKey` is passed to the `OrderBy` clause to indicate the sort keys and their sort direction. - */ -public enum SortKey { - - /** - Indicates that the `KeyPathString` should be sorted in ascending order - */ - case ascending(KeyPathString) - - /** - Indicates that the `KeyPathString` should be sorted in descending order - */ - case descending(KeyPathString) -} - - // MARK: - OrderBy /** The `OrderBy` clause specifies the sort order for results for a fetch or a query. */ -public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { +public struct OrderBy: OrderByClause, FetchClause, QueryClause, DeleteClause, Hashable { /** Combines two `OrderBy` sort descriptors together @@ -74,11 +55,6 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { left = left + right } - /** - The list of sort descriptors - */ - public let sortDescriptors: [NSSortDescriptor] - /** Initializes a `OrderBy` clause with an empty list of sort descriptors */ @@ -112,21 +88,9 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { - parameter sortKey: a series of `SortKey`s */ - public init(_ sortKey: [SortKey]) { + public init(_ sortKeys: [SortKey]) { - self.init( - sortKey.map { sortKey -> NSSortDescriptor in - - switch sortKey { - - case .ascending(let keyPath): - return NSSortDescriptor(key: keyPath, ascending: true) - - case .descending(let keyPath): - return NSSortDescriptor(key: keyPath, ascending: false) - } - } - ) + self.init(sortKeys.map({ $0.descriptor })) } /** @@ -141,6 +105,13 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { } + // MARK: OrderByClause + + public typealias ObjectType = D + + public let sortDescriptors: [NSSortDescriptor] + + // MARK: FetchClause, QueryClause, DeleteClause public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { @@ -171,17 +142,154 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { return (self.sortDescriptors as NSArray).hashValue } + + + // MARK: - SortKey + + /** + The `SortKey` is passed to the `OrderBy` clause to indicate the sort keys and their sort direction. + */ + public struct SortKey { + + // MARK: Raw Key Paths + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ keyPath: KeyPathString) -> SortKey { + + return SortKey(descriptor: .init(key: keyPath, ascending: true)) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ keyPath: KeyPathString) -> SortKey { + + return SortKey(descriptor: .init(key: keyPath, ascending: false)) + } + + + // MARK: NSManagedObject Key Paths + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ keyPath: KeyPath) -> SortKey where D: NSManagedObject { + + return .ascending(keyPath._kvcKeyPathString!) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ keyPath: KeyPath) -> SortKey where D: NSManagedObject { + + return .descending(keyPath._kvcKeyPathString!) + } + + + // MARK: CoreStoreObject Key Paths + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ attribute: KeyPath) -> SortKey where A: ValueContainer.Required { + + return .ascending(D.meta[keyPath: attribute].keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ attribute: KeyPath) -> SortKey where A: ValueContainer.Optional { + + return .ascending(D.meta[keyPath: attribute].keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ attribute: KeyPath) -> SortKey where A: TransformableContainer.Required { + + return .ascending(D.meta[keyPath: attribute].keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ attribute: KeyPath) -> SortKey where A: TransformableContainer.Optional { + + return .ascending(D.meta[keyPath: attribute].keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ attribute: KeyPath) -> SortKey where A: ValueContainer.Required { + + return .descending(D.meta[keyPath: attribute].keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ attribute: KeyPath) -> SortKey where A: ValueContainer.Optional { + + return .descending(D.meta[keyPath: attribute].keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ attribute: KeyPath) -> SortKey where A: TransformableContainer.Required { + + return .descending(D.meta[keyPath: attribute].keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ attribute: KeyPath) -> SortKey where A: TransformableContainer.Optional { + + return .descending(D.meta[keyPath: attribute].keyPath) + } + + + // MARK: Private + + fileprivate let descriptor: NSSortDescriptor + } } -// MARK: - Sequence where Element == OrderBy +// MARK: - OrderByClause -public extension Sequence where Iterator.Element == OrderBy { +/** + Abstracts the `OrderBy` clause for protocol utilities. + */ +public protocol OrderByClause { + + /** + The `DynamicObject` type associated with the clause + */ + associatedtype ObjectType: DynamicObject + + /** + The `NSSortDescriptor` array for the fetch or query + */ + var sortDescriptors: [NSSortDescriptor] { get } +} + + +// MARK: - Sequence where Iterator.Element: OrderByClause + +public extension Sequence where Iterator.Element: OrderByClause { /** Combines multiple `OrderBy` predicates together */ - public func combined() -> OrderBy { + public func combined() -> OrderBy { return OrderBy(self.flatMap({ $0.sortDescriptors })) } diff --git a/Sources/QueryableSource.swift b/Sources/QueryableSource.swift index 4b40a42..a844827 100644 --- a/Sources/QueryableSource.swift +++ b/Sources/QueryableSource.swift @@ -44,7 +44,7 @@ public protocol QueryableSource: class { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? + func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? /** Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. @@ -56,7 +56,7 @@ public protocol QueryableSource: class { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? + func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? /** Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. @@ -68,7 +68,7 @@ public protocol QueryableSource: class { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? + func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? /** Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. @@ -80,7 +80,7 @@ public protocol QueryableSource: class { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? + func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? /** The internal `NSManagedObjectContext` managed by this `QueryableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases. diff --git a/Sources/SynchronousDataTransaction.swift b/Sources/SynchronousDataTransaction.swift index 7f5d3d8..8176dfd 100644 --- a/Sources/SynchronousDataTransaction.swift +++ b/Sources/SynchronousDataTransaction.swift @@ -55,7 +55,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type. */ - public override func create(_ into: Into) -> T { + public override func create(_ into: Into) -> D { CoreStore.assert( !self.isCommitted, @@ -71,7 +71,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. */ - public override func edit(_ object: T?) -> T? { + public override func edit(_ object: D?) -> D? { CoreStore.assert( !self.isCommitted, @@ -88,7 +88,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - parameter objectID: the `NSManagedObjectID` for the object to be edited - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. */ - public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { + public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> D? { CoreStore.assert( !self.isCommitted, @@ -103,7 +103,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - parameter object: the `NSManagedObject` or `CoreStoreObject` type to be deleted */ - public override func delete(_ object: T?) { + public override func delete(_ object: D?) { CoreStore.assert( !self.isCommitted, @@ -120,7 +120,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - parameter object2: another `DynamicObject` to be deleted - parameter objects: other `DynamicObject`s to be deleted */ - public override func delete(_ object1: T?, _ object2: T?, _ objects: T?...) { + public override func delete(_ object1: D?, _ object2: D?, _ objects: D?...) { CoreStore.assert( !self.isCommitted, diff --git a/Sources/UnsafeDataTransaction+Observing.swift b/Sources/UnsafeDataTransaction+Observing.swift index 02cbd03..181f28b 100644 --- a/Sources/UnsafeDataTransaction+Observing.swift +++ b/Sources/UnsafeDataTransaction+Observing.swift @@ -38,7 +38,7 @@ public extension UnsafeDataTransaction { - parameter object: the `DynamicObject` to observe changes from - returns: a `ObjectMonitor` that monitors changes to `object` */ - public func monitorObject(_ object: T) -> ObjectMonitor { + public func monitorObject(_ object: D) -> ObjectMonitor { return ObjectMonitor( unsafeTransaction: self, @@ -53,7 +53,7 @@ public extension UnsafeDataTransaction { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { + public func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { return self.monitorList(from, fetchClauses) } @@ -65,10 +65,10 @@ public extension UnsafeDataTransaction { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { + public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { CoreStore.assert( - fetchClauses.filter { $0 is OrderBy }.count > 0, + fetchClauses.filter { $0 is OrderBy }.count > 0, "A ListMonitor requires an OrderBy clause." ) @@ -90,7 +90,7 @@ public extension UnsafeDataTransaction { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } @@ -102,10 +102,10 @@ public extension UnsafeDataTransaction { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { CoreStore.assert( - fetchClauses.filter { $0 is OrderBy }.count > 0, + fetchClauses.filter { $0 is OrderBy }.count > 0, "A ListMonitor requires an OrderBy clause." ) @@ -129,7 +129,7 @@ public extension UnsafeDataTransaction { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { + public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { return self.monitorSectionedList(from, sectionBy, fetchClauses) } @@ -142,10 +142,10 @@ public extension UnsafeDataTransaction { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { + public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { CoreStore.assert( - fetchClauses.filter { $0 is OrderBy }.count > 0, + fetchClauses.filter { $0 is OrderBy }.count > 0, "A ListMonitor requires an OrderBy clause." ) @@ -168,7 +168,7 @@ public extension UnsafeDataTransaction { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } @@ -181,10 +181,10 @@ public extension UnsafeDataTransaction { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { CoreStore.assert( - fetchClauses.filter { $0 is OrderBy }.count > 0, + fetchClauses.filter { $0 is OrderBy }.count > 0, "A ListMonitor requires an OrderBy clause." ) diff --git a/Sources/Where+NSManagedObject.swift b/Sources/Where+NSManagedObject.swift new file mode 100644 index 0000000..ef73499 --- /dev/null +++ b/Sources/Where+NSManagedObject.swift @@ -0,0 +1,220 @@ +// +// Where+NSManagedObject.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 CoreData +import Foundation + + +// MARK: - KeyPath where Root: NSManagedObject, Value: QueryableAttributeType & Equatable + +public extension KeyPath where Root: NSManagedObject, Value: QueryableAttributeType & Equatable { + + public static func == (_ keyPath: KeyPath, _ value: Value) -> Where { + + return Where(keyPath._kvcKeyPathString!, isEqualTo: value) + } + + public static func != (_ keyPath: KeyPath, _ value: Value) -> Where { + + return !Where(keyPath._kvcKeyPathString!, isEqualTo: value) + } + + public static func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where S.Iterator.Element == Value { + + return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) + } +} + +// MARK: - KeyPath where Root: NSManagedObject, Value: Optional + +public extension KeyPath where Root: NSManagedObject { + + public static func == (_ keyPath: KeyPath, _ value: Value) -> Where where Value == Optional { + + return Where(keyPath._kvcKeyPathString!, isEqualTo: value) + } + + public static func != (_ keyPath: KeyPath, _ value: Value) -> Where where Value == Optional { + + return !Where(keyPath._kvcKeyPathString!, isEqualTo: value) + } + + public static func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where Value == Optional, S.Iterator.Element == V { + + return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) + } +} + + +// MARK: - KeyPath where Root: NSManagedObject, Value: QueryableAttributeType + +public extension KeyPath where Root: NSManagedObject, Value: QueryableAttributeType { + + public static func < (_ keyPath: KeyPath, _ value: Value) -> Where { + + return Where("%K < %@", keyPath._kvcKeyPathString!, value) + } + + public static func > (_ keyPath: KeyPath, _ value: Value) -> Where { + + return Where("%K > %@", keyPath._kvcKeyPathString!, value) + } + + public static func <= (_ keyPath: KeyPath, _ value: Value) -> Where { + + return Where("%K <= %@", keyPath._kvcKeyPathString!, value) + } + + public static func >= (_ keyPath: KeyPath, _ value: Value) -> Where { + + return Where("%K >= %@", keyPath._kvcKeyPathString!, value) + } +} + + +// MARK: - KeyPath where Root: NSManagedObject, Value: Optional + +public extension KeyPath where Root: NSManagedObject { + + public static func < (_ keyPath: KeyPath, _ value: Value) -> Where where Value == Optional { + + if let value = value { + + return Where("%K < %@", keyPath._kvcKeyPathString!, value) + } + else { + + return Where("%K < nil", keyPath._kvcKeyPathString!) + } + } + + public static func > (_ keyPath: KeyPath, _ value: Value) -> Where where Value == Optional { + + if let value = value { + + return Where("%K > %@", keyPath._kvcKeyPathString!, value) + } + else { + + return Where("%K > nil", keyPath._kvcKeyPathString!) + } + } + + public static func <= (_ keyPath: KeyPath, _ value: Value) -> Where where Value == Optional { + + if let value = value { + + return Where("%K <= %@", keyPath._kvcKeyPathString!, value) + } + else { + + return Where("%K <= nil", keyPath._kvcKeyPathString!) + } + } + + public static func >= (_ keyPath: KeyPath, _ value: Value) -> Where where Value == Optional { + + if let value = value { + + return Where("%K >= %@", keyPath._kvcKeyPathString!, value) + } + else { + + return Where("%K >= nil", keyPath._kvcKeyPathString!) + } + } +} + + +// MARK: - KeyPath where Root: NSManagedObject, Value: NSManagedObject + +public extension KeyPath where Root: NSManagedObject, Value: NSManagedObject { + + public static func == (_ keyPath: KeyPath, _ object: Value) -> Where { + + return Where(keyPath._kvcKeyPathString!, isEqualTo: object) + } + + public static func != (_ keyPath: KeyPath, _ object: Value) -> Where { + + return !Where(keyPath._kvcKeyPathString!, isEqualTo: object) + } + + public static func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where S.Iterator.Element == Value { + + return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) + } + + public static func == (_ keyPath: KeyPath, _ objectID: NSManagedObjectID?) -> Where { + + return Where(keyPath._kvcKeyPathString!, isEqualTo: objectID) + } + + public static func != (_ keyPath: KeyPath, _ objectID: NSManagedObjectID?) -> Where { + + return !Where(keyPath._kvcKeyPathString!, isEqualTo: objectID) + } + + public static func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where S.Iterator.Element == NSManagedObjectID { + + return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) + } +} + + +// MARK: - KeyPath where Root: NSManagedObject, Value: Optional + +public extension KeyPath where Root: NSManagedObject { + + public static func == (_ keyPath: KeyPath, _ object: Value) -> Where where Value == Optional { + + return Where(keyPath._kvcKeyPathString!, isEqualTo: object) + } + + public static func != (_ keyPath: KeyPath, _ object: Value) -> Where where Value == Optional { + + return !Where(keyPath._kvcKeyPathString!, isEqualTo: object) + } + + public static func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where Value == Optional, S.Iterator.Element == V { + + return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) + } + + public static func == (_ keyPath: KeyPath, _ objectID: NSManagedObjectID?) -> Where where Value == Optional { + + return Where(keyPath._kvcKeyPathString!, isEqualTo: objectID) + } + + public static func != (_ keyPath: KeyPath, _ objectID: NSManagedObjectID?) -> Where where Value == Optional { + + return !Where(keyPath._kvcKeyPathString!, isEqualTo: objectID) + } + + public static func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where Value == Optional, S.Iterator.Element == NSManagedObjectID { + + return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) + } +} diff --git a/Sources/Where.swift b/Sources/Where.swift index 65cea6a..b8b6fdd 100644 --- a/Sources/Where.swift +++ b/Sources/Where.swift @@ -32,7 +32,7 @@ import CoreData /** The `Where` clause specifies the conditions for a fetch or a query. */ -public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { +public struct Where: WhereClause, FetchClause, QueryClause, DeleteClause, Hashable { /** Combines two `Where` predicates together using `AND` operator @@ -126,11 +126,6 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { return Where(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate])) } - /** - The `NSPredicate` for the fetch or query - */ - public let predicate: NSPredicate - /** Initializes a `Where` clause with a predicate that always evaluates to `true` */ @@ -188,7 +183,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { - parameter keyPath: the keyPath to compare with - parameter value: the arguments for the `==` operator */ - public init(_ keyPath: KeyPathString, isEqualTo value: T?) { + public init(_ keyPath: KeyPathString, isEqualTo value: U?) { switch value { @@ -207,12 +202,11 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { - parameter keyPath: the keyPath to compare with - parameter object: the arguments for the `==` operator */ - public init(_ keyPath: KeyPathString, isEqualTo object: T?) { + public init(_ keyPath: KeyPathString, isEqualTo object: D?) { switch object { - case nil, - is NSNull: + case nil: self.init(NSPredicate(format: "\(keyPath) == nil")) case let object?: @@ -220,6 +214,17 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { } } + /** + Initializes a `Where` clause that compares equality + + - parameter keyPath: the keyPath to compare with + - parameter objectID: the arguments for the `==` operator + */ + public init(_ keyPath: KeyPathString, isEqualTo objectID: NSManagedObjectID) { + + self.init(NSPredicate(format: "\(keyPath) == %@", argumentArray: [objectID])) + } + /** Initializes a `Where` clause that compares membership @@ -242,6 +247,17 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0.cs_id() }) as NSArray)) } + /** + Initializes a `Where` clause that compares membership + + - parameter keyPath: the keyPath to compare with + - parameter list: the sequence to check membership of + */ + public init(_ keyPath: KeyPathString, isMemberOf list: S) where S.Iterator.Element: NSManagedObjectID { + + self.init(NSPredicate(format: "\(keyPath) IN %@", list.map({ $0 }) as NSArray)) + } + /** Initializes a `Where` clause with an `NSPredicate` @@ -253,6 +269,13 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { } + // MARK: WhereClause + + public typealias ObjectType = D + + public let predicate: NSPredicate + + // MARK: FetchClause, QueryClause, DeleteClause public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { @@ -286,14 +309,33 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { } -// MARK: - Sequence where Element == Where +// MARK: - WhereClause -public extension Sequence where Iterator.Element == Where { +/** + Abstracts the `Where` clause for protocol utilities. + */ +public protocol WhereClause { + + /** + The `DynamicObject` type associated with the clause + */ + associatedtype ObjectType: DynamicObject + + /** + The `NSPredicate` for the fetch or query + */ + var predicate: NSPredicate { get } +} + + +// MARK: - Sequence where Iterator.Element: WhereClause + +public extension Sequence where Iterator.Element: WhereClause { /** Combines multiple `Where` predicates together using `AND` operator */ - public func combinedByAnd() -> Where { + public func combinedByAnd() -> Where { return Where(NSCompoundPredicate(type: .and, subpredicates: self.map({ $0.predicate }))) } @@ -301,7 +343,7 @@ public extension Sequence where Iterator.Element == Where { /** Combines multiple `Where` predicates together using `OR` operator */ - public func combinedByOr() -> Where { + public func combinedByOr() -> Where { return Where(NSCompoundPredicate(type: .or, subpredicates: self.map({ $0.predicate }))) }