WIP: query chains!

This commit is contained in:
John Rommel Estropia
2017-07-09 10:44:53 +09:00
parent aff966aac9
commit 535eb76adc
40 changed files with 1783 additions and 1004 deletions

View File

@@ -324,10 +324,10 @@
B5519A601CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; }; B5519A601CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; };
B5519A611CA21954002BEF78 /* 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 */; }; B5519A621CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; };
B55514EA1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; }; B55514EA1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */; };
B55514EB1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; }; B55514EB1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */; };
B55514EC1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.swift */; }; B55514EC1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */; };
B55514ED1EED8BF900BAB888 /* FetchCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55514E91EED8BF900BAB888 /* FetchCondition.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, ); }; }; 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, ); }; }; 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, ); }; }; 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 */; }; B59FA0B01CCBACA7007C9BCA /* ICloudStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59FA0AD1CCBAC95007C9BCA /* ICloudStore.swift */; };
B59FA0B11CCBACA7007C9BCA /* 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 */; }; 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 */; }; B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A261201B64BFDB006EB6D3 /* MigrationType.swift */; };
B5A5F2661CAEC50F004AB9AF /* CSSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A5F2651CAEC50F004AB9AF /* CSSelect.swift */; }; B5A5F2661CAEC50F004AB9AF /* CSSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A5F2651CAEC50F004AB9AF /* CSSelect.swift */; };
B5A5F2681CAEC50F004AB9AF /* 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 = "<group>"; }; B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSAsynchronousDataTransaction.swift; sourceTree = "<group>"; };
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; }; 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; }; 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 = "<group>"; }; B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChainedClauseBuilder.swift; sourceTree = "<group>"; };
B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreStoreBridge.h; sourceTree = "<group>"; }; B55717421D15AF9C009BDBCA /* CoreStoreBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreStoreBridge.h; sourceTree = "<group>"; };
B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSetupResult.swift; sourceTree = "<group>"; }; B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSetupResult.swift; sourceTree = "<group>"; };
B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSStorageInterface.swift; sourceTree = "<group>"; }; B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSStorageInterface.swift; sourceTree = "<group>"; };
@@ -827,6 +831,7 @@
B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryableSource.swift; sourceTree = "<group>"; }; B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryableSource.swift; sourceTree = "<group>"; };
B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSPersistentStoreCoordinator+Setup.swift"; sourceTree = "<group>"; }; B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSPersistentStoreCoordinator+Setup.swift"; sourceTree = "<group>"; };
B59FA0AD1CCBAC95007C9BCA /* ICloudStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ICloudStore.swift; sourceTree = "<group>"; }; B59FA0AD1CCBAC95007C9BCA /* ICloudStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ICloudStore.swift; sourceTree = "<group>"; };
B5A1DAC71F111BFA003CF369 /* Where+NSManagedObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Where+NSManagedObject.swift"; sourceTree = "<group>"; };
B5A261201B64BFDB006EB6D3 /* MigrationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationType.swift; sourceTree = "<group>"; }; B5A261201B64BFDB006EB6D3 /* MigrationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationType.swift; sourceTree = "<group>"; };
B5A5F2651CAEC50F004AB9AF /* CSSelect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSelect.swift; sourceTree = "<group>"; }; B5A5F2651CAEC50F004AB9AF /* CSSelect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSelect.swift; sourceTree = "<group>"; };
B5A991EB1E9DC2CE0091A2E3 /* VersionLock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionLock.swift; sourceTree = "<group>"; }; B5A991EB1E9DC2CE0091A2E3 /* VersionLock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionLock.swift; sourceTree = "<group>"; };
@@ -1251,6 +1256,15 @@
name = "Dynamic Models"; name = "Dynamic Models";
sourceTree = "<group>"; sourceTree = "<group>";
}; };
B5A1DAC61F111BBE003CF369 /* KeyPath Utilities */ = {
isa = PBXGroup;
children = (
B5A1DAC71F111BFA003CF369 /* Where+NSManagedObject.swift */,
B5D339EB1E9495E500C880DE /* CoreStoreObject+Querying.swift */,
);
name = "KeyPath Utilities";
sourceTree = "<group>";
};
B5A5F26B1CAFF8D0004AB9AF /* Swift */ = { B5A5F26B1CAFF8D0004AB9AF /* Swift */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@@ -1374,14 +1388,14 @@
B5E84EFD1AFF847B0064E85B /* Fetching and Querying */ = { B5E84EFD1AFF847B0064E85B /* Fetching and Querying */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
B5D339EB1E9495E500C880DE /* CoreStoreObject+Querying.swift */,
B5E84EFE1AFF847B0064E85B /* BaseDataTransaction+Querying.swift */, B5E84EFE1AFF847B0064E85B /* BaseDataTransaction+Querying.swift */,
B5E84F061AFF847B0064E85B /* DataStack+Querying.swift */, B5E84F061AFF847B0064E85B /* DataStack+Querying.swift */,
B5E84F071AFF847B0064E85B /* CoreStore+Querying.swift */, B5E84F071AFF847B0064E85B /* CoreStore+Querying.swift */,
B596BBB51DD5BC67001DCDD9 /* FetchableSource.swift */, B596BBB51DD5BC67001DCDD9 /* FetchableSource.swift */,
B55514E91EED8BF900BAB888 /* FetchCondition.swift */, B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */,
B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */, B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */,
B549F65D1E569C7400FBAB2D /* QueryableAttributeType.swift */, B549F65D1E569C7400FBAB2D /* QueryableAttributeType.swift */,
B5A1DAC61F111BBE003CF369 /* KeyPath Utilities */,
B5E84F0A1AFF847B0064E85B /* Protocol Clauses */, B5E84F0A1AFF847B0064E85B /* Protocol Clauses */,
B5E84EFF1AFF847B0064E85B /* Concrete Clauses */, B5E84EFF1AFF847B0064E85B /* Concrete Clauses */,
); );
@@ -1800,7 +1814,7 @@
B5D339D81E9489AB00C880DE /* CoreStoreObject.swift in Sources */, B5D339D81E9489AB00C880DE /* CoreStoreObject.swift in Sources */,
B5D3F6451C887C0A00C7492A /* LegacySQLiteStore.swift in Sources */, B5D3F6451C887C0A00C7492A /* LegacySQLiteStore.swift in Sources */,
B56923FA1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, B56923FA1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */,
B55514EA1EED8BF900BAB888 /* FetchCondition.swift in Sources */, B55514EA1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */,
B596BBBB1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, B596BBBB1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */,
B5ECDBFF1CA80CBA00C7F112 /* CSWhere.swift in Sources */, B5ECDBFF1CA80CBA00C7F112 /* CSWhere.swift in Sources */,
B5ECDC051CA8138100C7F112 /* CSOrderBy.swift in Sources */, B5ECDC051CA8138100C7F112 /* CSOrderBy.swift in Sources */,
@@ -1860,6 +1874,7 @@
B501FDE71CA8D20500BE22EF /* CSListObserver.swift in Sources */, B501FDE71CA8D20500BE22EF /* CSListObserver.swift in Sources */,
B5E41EC01EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B5E41EC01EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */,
B501FDE21CA8D1F500BE22EF /* CSListMonitor.swift in Sources */, B501FDE21CA8D1F500BE22EF /* CSListMonitor.swift in Sources */,
B5A1DAC81F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */,
2F291E2719C6D3CF007AF63F /* CoreStore.swift in Sources */, 2F291E2719C6D3CF007AF63F /* CoreStore.swift in Sources */,
B5ECDC111CA816E500C7F112 /* CSTweak.swift in Sources */, B5ECDC111CA816E500C7F112 /* CSTweak.swift in Sources */,
B56923C41EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, B56923C41EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */,
@@ -1987,7 +2002,7 @@
B5D339D91E9489AB00C880DE /* CoreStoreObject.swift in Sources */, B5D339D91E9489AB00C880DE /* CoreStoreObject.swift in Sources */,
82BA18CE1C4BBD7100A0916E /* FetchedResultsControllerDelegate.swift in Sources */, 82BA18CE1C4BBD7100A0916E /* FetchedResultsControllerDelegate.swift in Sources */,
B56923FB1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, B56923FB1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */,
B55514EB1EED8BF900BAB888 /* FetchCondition.swift in Sources */, B55514EB1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */,
B596BBBC1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, B596BBBC1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */,
B5ECDC011CA80CBA00C7F112 /* CSWhere.swift in Sources */, B5ECDC011CA80CBA00C7F112 /* CSWhere.swift in Sources */,
B5ECDC071CA8138100C7F112 /* CSOrderBy.swift in Sources */, B5ECDC071CA8138100C7F112 /* CSOrderBy.swift in Sources */,
@@ -2047,6 +2062,7 @@
B501FDE91CA8D20500BE22EF /* CSListObserver.swift in Sources */, B501FDE91CA8D20500BE22EF /* CSListObserver.swift in Sources */,
B5E41EC11EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B5E41EC11EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */,
B501FDE41CA8D1F500BE22EF /* CSListMonitor.swift in Sources */, B501FDE41CA8D1F500BE22EF /* CSListMonitor.swift in Sources */,
B5A1DAC91F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */,
B5FE4DA31C8481E100FA6A91 /* StorageInterface.swift in Sources */, B5FE4DA31C8481E100FA6A91 /* StorageInterface.swift in Sources */,
B5ECDC131CA816E500C7F112 /* CSTweak.swift in Sources */, B5ECDC131CA816E500C7F112 /* CSTweak.swift in Sources */,
B56923C51EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, B56923C51EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */,
@@ -2174,7 +2190,7 @@
B5D339DB1E9489AB00C880DE /* CoreStoreObject.swift in Sources */, B5D339DB1E9489AB00C880DE /* CoreStoreObject.swift in Sources */,
B52DD1951BE1F92500949AFE /* CoreStoreError.swift in Sources */, B52DD1951BE1F92500949AFE /* CoreStoreError.swift in Sources */,
B56923FD1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, B56923FD1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */,
B55514ED1EED8BF900BAB888 /* FetchCondition.swift in Sources */, B55514ED1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */,
B596BBBE1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, B596BBBE1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */,
B546F9601C9A12B800D5AC55 /* CSSQliteStore.swift in Sources */, B546F9601C9A12B800D5AC55 /* CSSQliteStore.swift in Sources */,
B5ECDC0F1CA8161B00C7F112 /* CSGroupBy.swift in Sources */, B5ECDC0F1CA8161B00C7F112 /* CSGroupBy.swift in Sources */,
@@ -2234,6 +2250,7 @@
B559CD4D1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B559CD4D1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */,
B5E41EC31EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B5E41EC31EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */,
B5ECDBE91CA6BEA300C7F112 /* CSClauseTypes.swift in Sources */, B5ECDBE91CA6BEA300C7F112 /* CSClauseTypes.swift in Sources */,
B5A1DACB1F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */,
B52DD1B81BE1F94000949AFE /* DataStack+Migration.swift in Sources */, B52DD1B81BE1F94000949AFE /* DataStack+Migration.swift in Sources */,
B5ECDC091CA8138100C7F112 /* CSOrderBy.swift in Sources */, B5ECDC091CA8138100C7F112 /* CSOrderBy.swift in Sources */,
B56923C71EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, B56923C71EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */,
@@ -2361,7 +2378,7 @@
B5D339DA1E9489AB00C880DE /* CoreStoreObject.swift in Sources */, B5D339DA1E9489AB00C880DE /* CoreStoreObject.swift in Sources */,
B5ECDC021CA80CBA00C7F112 /* CSWhere.swift in Sources */, B5ECDC021CA80CBA00C7F112 /* CSWhere.swift in Sources */,
B56923FC1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, B56923FC1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */,
B55514EC1EED8BF900BAB888 /* FetchCondition.swift in Sources */, B55514EC1EED8BF900BAB888 /* ChainedClauseBuilder.swift in Sources */,
B596BBBD1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, B596BBBD1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */,
B5ECDC081CA8138100C7F112 /* CSOrderBy.swift in Sources */, B5ECDC081CA8138100C7F112 /* CSOrderBy.swift in Sources */,
B5E1B59B1CAA0C23007FD580 /* CSObjectObserver.swift in Sources */, B5E1B59B1CAA0C23007FD580 /* CSObjectObserver.swift in Sources */,
@@ -2421,6 +2438,7 @@
B501FDE51CA8D1F500BE22EF /* CSListMonitor.swift in Sources */, B501FDE51CA8D1F500BE22EF /* CSListMonitor.swift in Sources */,
B5E41EC21EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B5E41EC21EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */,
B5ECDC141CA816E500C7F112 /* CSTweak.swift in Sources */, B5ECDC141CA816E500C7F112 /* CSTweak.swift in Sources */,
B5A1DACA1F111BFA003CF369 /* Where+NSManagedObject.swift in Sources */,
B56321AE1BD6521C006C9394 /* NotificationObserver.swift in Sources */, B56321AE1BD6521C006C9394 /* NotificationObserver.swift in Sources */,
B56321931BD65216006C9394 /* DataStack+Querying.swift in Sources */, B56321931BD65216006C9394 /* DataStack+Querying.swift in Sources */,
B56923C61EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, B56923C61EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */,

View File

@@ -40,8 +40,8 @@ class ConvenienceTests: BaseTestCase {
let controller = stack.createFetchedResultsController( let controller = stack.createFetchedResultsController(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testString)), SectionBy(#keyPath(TestEntity1.testString)),
Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100), Where<TestEntity1>("%@ > %d", #keyPath(TestEntity1.testEntityID), 100),
OrderBy(.ascending(#keyPath(TestEntity1.testString))), OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testString))),
Tweak { $0.fetchLimit = 10 } Tweak { $0.fetchLimit = 10 }
) )
XCTAssertEqual(controller.managedObjectContext, stack.mainContext) XCTAssertEqual(controller.managedObjectContext, stack.mainContext)
@@ -49,11 +49,11 @@ class ConvenienceTests: BaseTestCase {
XCTAssertEqual(controller.sectionNameKeyPath, #keyPath(TestEntity1.testString)) XCTAssertEqual(controller.sectionNameKeyPath, #keyPath(TestEntity1.testString))
XCTAssertEqual( XCTAssertEqual(
controller.fetchRequest.sortDescriptors!, controller.fetchRequest.sortDescriptors!,
OrderBy(.ascending(#keyPath(TestEntity1.testString))).sortDescriptors OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testString))).sortDescriptors
) )
XCTAssertEqual( XCTAssertEqual(
controller.fetchRequest.predicate, controller.fetchRequest.predicate,
Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100).predicate Where<TestEntity1>("%@ > %d", #keyPath(TestEntity1.testEntityID), 100).predicate
) )
XCTAssertEqual(controller.fetchRequest.fetchLimit, 10) XCTAssertEqual(controller.fetchRequest.fetchLimit, 10)
} }
@@ -69,8 +69,8 @@ class ConvenienceTests: BaseTestCase {
let controller = transaction.createFetchedResultsController( let controller = transaction.createFetchedResultsController(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testString)), SectionBy(#keyPath(TestEntity1.testString)),
Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100), Where<TestEntity1>("%@ > %d", #keyPath(TestEntity1.testEntityID), 100),
OrderBy(.ascending(#keyPath(TestEntity1.testString))), OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testString))),
Tweak { $0.fetchLimit = 10 } Tweak { $0.fetchLimit = 10 }
) )
XCTAssertEqual(controller.managedObjectContext, transaction.context) XCTAssertEqual(controller.managedObjectContext, transaction.context)
@@ -78,11 +78,11 @@ class ConvenienceTests: BaseTestCase {
XCTAssertEqual(controller.sectionNameKeyPath, #keyPath(TestEntity1.testString)) XCTAssertEqual(controller.sectionNameKeyPath, #keyPath(TestEntity1.testString))
XCTAssertEqual( XCTAssertEqual(
controller.fetchRequest.sortDescriptors!, controller.fetchRequest.sortDescriptors!,
OrderBy(.ascending(#keyPath(TestEntity1.testString))).sortDescriptors OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testString))).sortDescriptors
) )
XCTAssertEqual( XCTAssertEqual(
controller.fetchRequest.predicate, controller.fetchRequest.predicate,
Where("%@ > %d", #keyPath(TestEntity1.testEntityID), 100).predicate Where<TestEntity1>("%@ > %d", #keyPath(TestEntity1.testEntityID), 100).predicate
) )
XCTAssertEqual(controller.fetchRequest.fetchLimit, 10) XCTAssertEqual(controller.fetchRequest.fetchLimit, 10)
} }

File diff suppressed because it is too large Load Diff

View File

@@ -444,7 +444,7 @@ class ImportTests: BaseTestDataTestCase {
XCTAssertNil(object) XCTAssertNil(object)
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5)
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)
@@ -620,7 +620,7 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 6) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 6)
let object = transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) let object = transaction.fetchOne(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))
XCTAssertNotNil(object) XCTAssertNotNil(object)
XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106))
XCTAssertNil(object?.testBoolean) XCTAssertNil(object?.testBoolean)
@@ -659,7 +659,7 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 6) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 6)
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) 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?.testData, ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!)
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!) XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!)
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)
@@ -866,8 +866,8 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5)
XCTAssertNil(transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))) XCTAssertNil(transaction.fetchOne(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)))
XCTAssertNil(transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 107))) XCTAssertNil(transaction.fetchOne(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 107)))
} }
transaction.unsafeContext().reset() transaction.unsafeContext().reset()
self.checkExpectationsImmediately() self.checkExpectationsImmediately()
@@ -910,7 +910,7 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
let object = transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) let object = transaction.fetchOne(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))
XCTAssertNotNil(object) XCTAssertNotNil(object)
XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106))
XCTAssertNil(object?.testBoolean) XCTAssertNil(object?.testBoolean)
@@ -953,7 +953,7 @@ class ImportTests: BaseTestDataTestCase {
errorExpectation.fulfill() errorExpectation.fulfill()
XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5) XCTAssertEqual(transaction.fetchCount(From<TestEntity1>()), 5)
let object = transaction.fetchOne(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) let object = transaction.fetchOne(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(object) XCTAssertNotNil(object)
XCTAssertEqual(object?.testEntityID, NSNumber(value: 105)) XCTAssertEqual(object?.testEntityID, NSNumber(value: 105))
XCTAssertEqual(object?.testBoolean, NSNumber(value: true)) 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?.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!)
XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!) XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!)
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)
@@ -1032,7 +1032,7 @@ class ImportTests: BaseTestDataTestCase {
XCTAssertEqual(object.testData, dictionary[(#keyPath(TestEntity1.testData))] as? Data) XCTAssertEqual(object.testData, dictionary[(#keyPath(TestEntity1.testData))] as? Data)
XCTAssertEqual(object.testDate, dictionary[(#keyPath(TestEntity1.testDate))] as? Date) XCTAssertEqual(object.testDate, dictionary[(#keyPath(TestEntity1.testDate))] as? Date)
} }
let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) let existingObjects = transaction.fetchAll(From<TestEntity1>(), Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 105))
XCTAssertNotNil(existingObjects) XCTAssertNotNil(existingObjects)
XCTAssertEqual(existingObjects?.count, 1) XCTAssertEqual(existingObjects?.count, 1)

View File

@@ -43,7 +43,7 @@ class ListObserverTests: BaseTestDataTestCase {
let monitor = stack.monitorSectionedList( let monitor = stack.monitorSectionedList(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testBoolean)), SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
) )
monitor.addObserver(observer) monitor.addObserver(observer)
@@ -171,7 +171,7 @@ class ListObserverTests: BaseTestDataTestCase {
let monitor = stack.monitorSectionedList( let monitor = stack.monitorSectionedList(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testBoolean)), SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
) )
monitor.addObserver(observer) monitor.addObserver(observer)
@@ -270,7 +270,7 @@ class ListObserverTests: BaseTestDataTestCase {
if let object = transaction.fetchOne( if let object = transaction.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) { Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) {
object.testNumber = NSNumber(value: 11) object.testNumber = NSNumber(value: 11)
object.testDecimal = NSDecimalNumber(string: "11") object.testDecimal = NSDecimalNumber(string: "11")
@@ -284,7 +284,7 @@ class ListObserverTests: BaseTestDataTestCase {
} }
if let object = transaction.fetchOne( if let object = transaction.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) { Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) {
object.testNumber = NSNumber(value: 22) object.testNumber = NSNumber(value: 22)
object.testDecimal = NSDecimalNumber(string: "22") object.testDecimal = NSDecimalNumber(string: "22")
@@ -323,7 +323,7 @@ class ListObserverTests: BaseTestDataTestCase {
let monitor = stack.monitorSectionedList( let monitor = stack.monitorSectionedList(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testBoolean)), SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
) )
monitor.addObserver(observer) monitor.addObserver(observer)
@@ -396,7 +396,7 @@ class ListObserverTests: BaseTestDataTestCase {
if let object = transaction.fetchOne( if let object = transaction.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) { Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) {
object.testBoolean = NSNumber(value: true) object.testBoolean = NSNumber(value: true)
} }
@@ -431,7 +431,7 @@ class ListObserverTests: BaseTestDataTestCase {
let monitor = stack.monitorSectionedList( let monitor = stack.monitorSectionedList(
From<TestEntity1>(), From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testBoolean)), SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
) )
monitor.addObserver(observer) monitor.addObserver(observer)
@@ -528,7 +528,7 @@ class ListObserverTests: BaseTestDataTestCase {
let count = transaction.deleteAll( let count = transaction.deleteAll(
From<TestEntity1>(), From<TestEntity1>(),
Where(#keyPath(TestEntity1.testBoolean), isEqualTo: false) Where<TestEntity1>(#keyPath(TestEntity1.testBoolean), isEqualTo: false)
) )
XCTAssertEqual(count, 2) XCTAssertEqual(count, 2)
return transaction.hasChanges return transaction.hasChanges

View File

@@ -43,7 +43,7 @@ class ObjectObserverTests: BaseTestDataTestCase {
guard let object = stack.fetchOne( guard let object = stack.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else {
XCTFail() XCTFail()
return return
@@ -140,7 +140,7 @@ class ObjectObserverTests: BaseTestDataTestCase {
guard let object = stack.fetchOne( guard let object = stack.fetchOne(
From<TestEntity1>(), From<TestEntity1>(),
Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else {
XCTFail() XCTFail()
return return

View File

@@ -38,21 +38,21 @@ final class OrderByTests: XCTestCase {
do { do {
let orderBy = OrderBy() let orderBy = OrderBy<NSManagedObject>()
XCTAssertEqual(orderBy, OrderBy([NSSortDescriptor]())) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>([NSSortDescriptor]()))
XCTAssertNotEqual(orderBy, OrderBy(NSSortDescriptor(key: "key", ascending: false))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(NSSortDescriptor(key: "key", ascending: false)))
XCTAssertTrue(orderBy.sortDescriptors.isEmpty) XCTAssertTrue(orderBy.sortDescriptors.isEmpty)
} }
do { do {
let sortDescriptor = NSSortDescriptor(key: "key1", ascending: true) let sortDescriptor = NSSortDescriptor(key: "key1", ascending: true)
let orderBy = OrderBy(sortDescriptor) let orderBy = OrderBy<NSManagedObject>(sortDescriptor)
XCTAssertEqual(orderBy, OrderBy(sortDescriptor)) XCTAssertEqual(orderBy, OrderBy(sortDescriptor))
XCTAssertEqual(orderBy, OrderBy(.ascending("key1"))) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1")))
XCTAssertNotEqual(orderBy, OrderBy(.ascending("key2"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key2")))
XCTAssertNotEqual(orderBy, OrderBy(.descending("key1"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.descending("key1")))
XCTAssertNotEqual(orderBy, OrderBy(NSSortDescriptor(key: "key1", ascending: false))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(NSSortDescriptor(key: "key1", ascending: false)))
XCTAssertEqual(orderBy, OrderBy([sortDescriptor])) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>([sortDescriptor]))
XCTAssertEqual(orderBy.sortDescriptors, [sortDescriptor]) XCTAssertEqual(orderBy.sortDescriptors, [sortDescriptor])
} }
do { do {
@@ -61,76 +61,76 @@ final class OrderByTests: XCTestCase {
NSSortDescriptor(key: "key1", ascending: true), NSSortDescriptor(key: "key1", ascending: true),
NSSortDescriptor(key: "key2", ascending: false) NSSortDescriptor(key: "key2", ascending: false)
] ]
let orderBy = OrderBy(sortDescriptors) let orderBy = OrderBy<NSManagedObject>(sortDescriptors)
XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(sortDescriptors))
XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key2")))
XCTAssertNotEqual( XCTAssertNotEqual(
orderBy, orderBy,
OrderBy( OrderBy<NSManagedObject>(
[ [
NSSortDescriptor(key: "key1", ascending: false), NSSortDescriptor(key: "key1", ascending: false),
NSSortDescriptor(key: "key2", ascending: false) NSSortDescriptor(key: "key2", ascending: false)
] ]
) )
) )
XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .ascending("key2")))
XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key3")))
XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors) XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors)
} }
do { do {
let orderBy = OrderBy(.ascending("key1")) let orderBy = OrderBy<NSManagedObject>(.ascending("key1"))
let sortDescriptor = NSSortDescriptor(key: "key1", ascending: true) let sortDescriptor = NSSortDescriptor(key: "key1", ascending: true)
XCTAssertEqual(orderBy, OrderBy(sortDescriptor)) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(sortDescriptor))
XCTAssertEqual(orderBy, OrderBy(.ascending("key1"))) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1")))
XCTAssertNotEqual(orderBy, OrderBy(.descending("key1"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.descending("key1")))
XCTAssertNotEqual(orderBy, OrderBy(.ascending("key2"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key2")))
XCTAssertEqual(orderBy, OrderBy([sortDescriptor])) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>([sortDescriptor]))
XCTAssertEqual(orderBy.sortDescriptors, [sortDescriptor]) XCTAssertEqual(orderBy.sortDescriptors, [sortDescriptor])
} }
do { do {
let orderBy = OrderBy(.ascending("key1"), .descending("key2")) let orderBy = OrderBy<NSManagedObject>(.ascending("key1"), .descending("key2"))
let sortDescriptors = [ let sortDescriptors = [
NSSortDescriptor(key: "key1", ascending: true), NSSortDescriptor(key: "key1", ascending: true),
NSSortDescriptor(key: "key2", ascending: false) NSSortDescriptor(key: "key2", ascending: false)
] ]
XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(sortDescriptors))
XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key2")))
XCTAssertNotEqual( XCTAssertNotEqual(
orderBy, orderBy,
OrderBy( OrderBy<NSManagedObject>(
[ [
NSSortDescriptor(key: "key1", ascending: false), NSSortDescriptor(key: "key1", ascending: false),
NSSortDescriptor(key: "key2", ascending: false) NSSortDescriptor(key: "key2", ascending: false)
] ]
) )
) )
XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .ascending("key2")))
XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key3")))
XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors) XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors)
} }
do { do {
let sortKeys: [SortKey] = [.ascending("key1"), .descending("key2")] let sortKeys: [OrderBy<NSManagedObject>.SortKey] = [.ascending("key1"), .descending("key2")]
let orderBy = OrderBy(sortKeys) let orderBy = OrderBy<NSManagedObject>(sortKeys)
let sortDescriptors = [ let sortDescriptors = [
NSSortDescriptor(key: "key1", ascending: true), NSSortDescriptor(key: "key1", ascending: true),
NSSortDescriptor(key: "key2", ascending: false) NSSortDescriptor(key: "key2", ascending: false)
] ]
XCTAssertEqual(orderBy, OrderBy(sortDescriptors)) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(sortDescriptors))
XCTAssertEqual(orderBy, OrderBy(.ascending("key1"), .descending("key2"))) XCTAssertEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key2")))
XCTAssertNotEqual( XCTAssertNotEqual(
orderBy, orderBy,
OrderBy( OrderBy<NSManagedObject>(
[ [
NSSortDescriptor(key: "key1", ascending: false), NSSortDescriptor(key: "key1", ascending: false),
NSSortDescriptor(key: "key2", ascending: false) NSSortDescriptor(key: "key2", ascending: false)
] ]
) )
) )
XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .ascending("key2"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .ascending("key2")))
XCTAssertNotEqual(orderBy, OrderBy(.ascending("key1"), .descending("key3"))) XCTAssertNotEqual(orderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key3")))
XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors) XCTAssertEqual(orderBy.sortDescriptors, sortDescriptors)
} }
} }
@@ -138,15 +138,15 @@ final class OrderByTests: XCTestCase {
@objc @objc
dynamic func test_ThatOrderByClauseOperations_ComputeCorrectly() { dynamic func test_ThatOrderByClauseOperations_ComputeCorrectly() {
let orderBy1 = OrderBy(.ascending("key1")) let orderBy1 = OrderBy<NSManagedObject>(.ascending("key1"))
let orderBy2 = OrderBy(.descending("key2")) let orderBy2 = OrderBy<NSManagedObject>(.descending("key2"))
let orderBy3 = OrderBy(.ascending("key3")) let orderBy3 = OrderBy<NSManagedObject>(.ascending("key3"))
do { do {
let plusOrderBy = orderBy1 + orderBy2 + orderBy3 let plusOrderBy = orderBy1 + orderBy2 + orderBy3
XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"), .ascending("key3"))) XCTAssertEqual(plusOrderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key2"), .ascending("key3")))
XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1")) + OrderBy(.descending("key2"), .ascending("key3"))) XCTAssertEqual(plusOrderBy, OrderBy<NSManagedObject>(.ascending("key1")) + OrderBy<NSManagedObject>(.descending("key2"), .ascending("key3")))
XCTAssertNotEqual(plusOrderBy, orderBy1 + orderBy3 + orderBy2) XCTAssertNotEqual(plusOrderBy, orderBy1 + orderBy3 + orderBy2)
XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1 + orderBy3) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1 + orderBy3)
XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy3 + orderBy1) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy3 + orderBy1)
@@ -158,14 +158,14 @@ final class OrderByTests: XCTestCase {
var plusOrderBy = orderBy1 var plusOrderBy = orderBy1
plusOrderBy += orderBy2 plusOrderBy += orderBy2
XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"))) XCTAssertEqual(plusOrderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key2")))
XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1")) + OrderBy(.descending("key2"))) XCTAssertEqual(plusOrderBy, OrderBy<NSManagedObject>(.ascending("key1")) + OrderBy<NSManagedObject>(.descending("key2")))
XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1)
XCTAssertEqual(plusOrderBy.sortDescriptors, orderBy1.sortDescriptors + orderBy2.sortDescriptors) XCTAssertEqual(plusOrderBy.sortDescriptors, orderBy1.sortDescriptors + orderBy2.sortDescriptors)
plusOrderBy += orderBy3 plusOrderBy += orderBy3
XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2"), .ascending("key3"))) XCTAssertEqual(plusOrderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key2"), .ascending("key3")))
XCTAssertEqual(plusOrderBy, OrderBy(.ascending("key1"), .descending("key2")) + OrderBy(.ascending("key3"))) XCTAssertEqual(plusOrderBy, OrderBy<NSManagedObject>(.ascending("key1"), .descending("key2")) + OrderBy<NSManagedObject>(.ascending("key3")))
XCTAssertNotEqual(plusOrderBy, orderBy1 + orderBy3 + orderBy2) XCTAssertNotEqual(plusOrderBy, orderBy1 + orderBy3 + orderBy2)
XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1 + orderBy3) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy1 + orderBy3)
XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy3 + orderBy1) XCTAssertNotEqual(plusOrderBy, orderBy2 + orderBy3 + orderBy1)
@@ -178,7 +178,7 @@ final class OrderByTests: XCTestCase {
@objc @objc
dynamic func test_ThatOrderByClauses_ApplyToFetchRequestsCorrectly() { dynamic func test_ThatOrderByClauses_ApplyToFetchRequestsCorrectly() {
let orderBy = OrderBy(.ascending("key")) let orderBy = OrderBy<NSManagedObject>(.ascending("key"))
let request = CoreStoreFetchRequest() let request = CoreStoreFetchRequest()
orderBy.applyToFetchRequest(request) orderBy.applyToFetchRequest(request)
XCTAssertNotNil(request.sortDescriptors) XCTAssertNotNil(request.sortDescriptors)

View File

@@ -43,7 +43,7 @@ class QueryTests: BaseTestDataTestCase {
let from = From<TestEntity1>(configurations) let from = From<TestEntity1>(configurations)
let queryClauses: [QueryClause] = [ let queryClauses: [QueryClause] = [
Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101) Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)
] ]
do { do {
@@ -227,8 +227,8 @@ class QueryTests: BaseTestDataTestCase {
let from = From<TestEntity1>(configurations) let from = From<TestEntity1>(configurations)
let queryClauses: [QueryClause] = [ let queryClauses: [QueryClause] = [
Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), Where<TestEntity1>("%K > %@", #keyPath(TestEntity1.testNumber), 1),
OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testEntityID)))
] ]
do { do {
@@ -406,7 +406,7 @@ class QueryTests: BaseTestDataTestCase {
let from = From<TestEntity1>(configurations) let from = From<TestEntity1>(configurations)
let queryClauses: [QueryClause] = [ let queryClauses: [QueryClause] = [
Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) Where<TestEntity1>("%K > %@", #keyPath(TestEntity1.testNumber), 1)
] ]
do { do {
@@ -583,7 +583,7 @@ class QueryTests: BaseTestDataTestCase {
let from = From<TestEntity1>(configurations) let from = From<TestEntity1>(configurations)
let queryClauses: [QueryClause] = [ let queryClauses: [QueryClause] = [
Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) Where<TestEntity1>("%K > %@", #keyPath(TestEntity1.testNumber), 1)
] ]
do { do {
@@ -767,7 +767,7 @@ class QueryTests: BaseTestDataTestCase {
let from = From<TestEntity1>(configurations) let from = From<TestEntity1>(configurations)
let queryClauses: [QueryClause] = [ let queryClauses: [QueryClause] = [
Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) Where<TestEntity1>("%K > %@", #keyPath(TestEntity1.testNumber), 1)
] ]
do { do {
@@ -951,7 +951,7 @@ class QueryTests: BaseTestDataTestCase {
let from = From<TestEntity1>(configurations) let from = From<TestEntity1>(configurations)
let queryClauses: [QueryClause] = [ let queryClauses: [QueryClause] = [
Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) Where<TestEntity1>("%K > %@", #keyPath(TestEntity1.testNumber), 1)
] ]
do { do {
@@ -1129,7 +1129,7 @@ class QueryTests: BaseTestDataTestCase {
let from = From<TestEntity1>(configurations) let from = From<TestEntity1>(configurations)
let queryClauses: [QueryClause] = [ let queryClauses: [QueryClause] = [
Where("%K > %@", #keyPath(TestEntity1.testNumber), 1) Where<TestEntity1>("%K > %@", #keyPath(TestEntity1.testNumber), 1)
] ]
do { do {
@@ -1297,8 +1297,8 @@ class QueryTests: BaseTestDataTestCase {
let from = From<TestEntity1>(configurations) let from = From<TestEntity1>(configurations)
let queryClauses: [QueryClause] = [ let queryClauses: [QueryClause] = [
Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), Where<TestEntity1>("%K > %@", #keyPath(TestEntity1.testNumber), 3),
OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testEntityID)))
] ]
do { do {

View File

@@ -396,7 +396,7 @@ final class TransactionTests: BaseTestCase {
let observer = TestListObserver() let observer = TestListObserver()
let monitor = stack.monitorList( let monitor = stack.monitorList(
From<TestEntity1>(), From<TestEntity1>(),
OrderBy(.ascending("testEntityID")) OrderBy<TestEntity1>(.ascending("testEntityID"))
) )
monitor.addObserver(observer) monitor.addObserver(observer)

View File

@@ -31,12 +31,12 @@ import CoreStore
// MARK: - XCTAssertAllEqual // MARK: - XCTAssertAllEqual
private func XCTAssertAllEqual(_ whereClauses: Where...) { private func XCTAssertAllEqual<D: DynamicObject>(_ whereClauses: Where<D>...) {
XCTAssertAllEqual(whereClauses) XCTAssertAllEqual(whereClauses)
} }
private func XCTAssertAllEqual(_ whereClauses: [Where]) { private func XCTAssertAllEqual<D: DynamicObject>(_ whereClauses: [Where<D>]) {
for i in whereClauses.indices { for i in whereClauses.indices {
@@ -57,51 +57,51 @@ final class WhereTests: XCTestCase {
do { do {
let whereClause = Where() let whereClause = Where<NSManagedObject>()
XCTAssertEqual(whereClause, Where(true)) XCTAssertEqual(whereClause, Where<NSManagedObject>(true))
XCTAssertNotEqual(whereClause, Where(false)) XCTAssertNotEqual(whereClause, Where<NSManagedObject>(false))
XCTAssertEqual(whereClause.predicate, NSPredicate(value: true)) XCTAssertEqual(whereClause.predicate, NSPredicate(value: true))
} }
do { do {
let whereClause = Where(true) let whereClause = Where<NSManagedObject>(true)
XCTAssertEqual(whereClause, Where()) XCTAssertEqual(whereClause, Where<NSManagedObject>())
XCTAssertNotEqual(whereClause, Where(false)) XCTAssertNotEqual(whereClause, Where<NSManagedObject>(false))
XCTAssertEqual(whereClause.predicate, NSPredicate(value: true)) XCTAssertEqual(whereClause.predicate, NSPredicate(value: true))
} }
do { do {
let predicate = NSPredicate(format: "%K == %@", "key", "value") let predicate = NSPredicate(format: "%K == %@", "key", "value")
let whereClause = Where(predicate) let whereClause = Where<NSManagedObject>(predicate)
XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause, Where<NSManagedObject>(predicate))
XCTAssertEqual(whereClause.predicate, predicate) XCTAssertEqual(whereClause.predicate, predicate)
} }
do { do {
let whereClause = Where("%K == %@", "key", "value") let whereClause = Where<NSManagedObject>("%K == %@", "key", "value")
let predicate = NSPredicate(format: "%K == %@", "key", "value") let predicate = NSPredicate(format: "%K == %@", "key", "value")
XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause, Where<NSManagedObject>(predicate))
XCTAssertEqual(whereClause.predicate, predicate) XCTAssertEqual(whereClause.predicate, predicate)
} }
do { do {
let whereClause = Where("%K == %@", argumentArray: ["key", "value"]) let whereClause = Where<NSManagedObject>("%K == %@", argumentArray: ["key", "value"])
let predicate = NSPredicate(format: "%K == %@", "key", "value") let predicate = NSPredicate(format: "%K == %@", "key", "value")
XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause, Where<NSManagedObject>(predicate))
XCTAssertEqual(whereClause.predicate, predicate) XCTAssertEqual(whereClause.predicate, predicate)
} }
do { do {
let whereClause = Where("key", isEqualTo: "value") let whereClause = Where<NSManagedObject>("key", isEqualTo: "value")
let predicate = NSPredicate(format: "%K == %@", "key", "value") let predicate = NSPredicate(format: "%K == %@", "key", "value")
XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause, Where<NSManagedObject>(predicate))
XCTAssertEqual(whereClause.predicate, predicate) XCTAssertEqual(whereClause.predicate, predicate)
} }
do { do {
let whereClause = Where("key", isMemberOf: ["value1", "value2", "value3"]) let whereClause = Where<NSManagedObject>("key", isMemberOf: ["value1", "value2", "value3"])
let predicate = NSPredicate(format: "%K IN %@", "key", ["value1", "value2", "value3"]) let predicate = NSPredicate(format: "%K IN %@", "key", ["value1", "value2", "value3"])
XCTAssertEqual(whereClause, Where(predicate)) XCTAssertEqual(whereClause, Where<NSManagedObject>(predicate))
XCTAssertEqual(whereClause.predicate, predicate) XCTAssertEqual(whereClause.predicate, predicate)
} }
} }
@@ -113,112 +113,112 @@ final class WhereTests: XCTestCase {
let value: Int = 100 let value: Int = 100
XCTAssertAllEqual( XCTAssertAllEqual(
Where("%K == %d", "key", value), Where<NSManagedObject>("%K == %d", "key", value),
Where("%K == %d", "key", value as AnyObject), Where<NSManagedObject>("%K == %d", "key", value as AnyObject),
Where("%K == %d", "key", NSNumber(value: value)), Where<NSManagedObject>("%K == %d", "key", NSNumber(value: value)),
Where("%K == %@", "key", value), Where<NSManagedObject>("%K == %@", "key", value),
Where("%K == %@", "key", value as AnyObject), Where<NSManagedObject>("%K == %@", "key", value as AnyObject),
Where("%K == %@", "key", NSNumber(value: value)), Where<NSManagedObject>("%K == %@", "key", NSNumber(value: value)),
Where("key", isEqualTo: value), Where<NSManagedObject>("key", isEqualTo: value),
Where("key", isEqualTo: NSNumber(value: value)) Where<NSManagedObject>("key", isEqualTo: NSNumber(value: value))
) )
} }
do { do {
let value = NSNumber(value: 100) let value = NSNumber(value: 100)
XCTAssertAllEqual( XCTAssertAllEqual(
Where("%K == %d", "key", value), Where<NSManagedObject>("%K == %d", "key", value),
Where("%K == %d", "key", value as AnyObject), Where<NSManagedObject>("%K == %d", "key", value as AnyObject),
Where("%K == %d", "key", value.intValue), Where<NSManagedObject>("%K == %d", "key", value.intValue),
Where("%K == %@", "key", value), Where<NSManagedObject>("%K == %@", "key", value),
Where("%K == %@", "key", value as AnyObject), Where<NSManagedObject>("%K == %@", "key", value as AnyObject),
Where("%K == %@", "key", value.intValue), Where<NSManagedObject>("%K == %@", "key", value.intValue),
Where("key", isEqualTo: value), Where<NSManagedObject>("key", isEqualTo: value),
Where("key", isEqualTo: value.intValue) Where<NSManagedObject>("key", isEqualTo: value.intValue)
) )
} }
do { do {
let value: Int64 = Int64.max let value: Int64 = Int64.max
XCTAssertAllEqual( XCTAssertAllEqual(
Where("%K == %d", "key", value), Where<NSManagedObject>("%K == %d", "key", value),
Where("%K == %d", "key", value as AnyObject), Where<NSManagedObject>("%K == %d", "key", value as AnyObject),
Where("%K == %d", "key", NSNumber(value: value)), Where<NSManagedObject>("%K == %d", "key", NSNumber(value: value)),
Where("%K == %@", "key", value), Where<NSManagedObject>("%K == %@", "key", value),
Where("%K == %@", "key", value as AnyObject), Where<NSManagedObject>("%K == %@", "key", value as AnyObject),
Where("%K == %@", "key", NSNumber(value: value)), Where<NSManagedObject>("%K == %@", "key", NSNumber(value: value)),
Where("key", isEqualTo: value), Where<NSManagedObject>("key", isEqualTo: value),
Where("key", isEqualTo: NSNumber(value: value)) Where<NSManagedObject>("key", isEqualTo: NSNumber(value: value))
) )
} }
do { do {
let value = NSNumber(value: Int64.max) let value = NSNumber(value: Int64.max)
XCTAssertAllEqual( XCTAssertAllEqual(
Where("%K == %d", "key", value), Where<NSManagedObject>("%K == %d", "key", value),
Where("%K == %d", "key", value as AnyObject), Where<NSManagedObject>("%K == %d", "key", value as AnyObject),
Where("%K == %d", "key", value.int64Value), Where<NSManagedObject>("%K == %d", "key", value.int64Value),
Where("%K == %@", "key", value), Where<NSManagedObject>("%K == %@", "key", value),
Where("%K == %@", "key", value as AnyObject), Where<NSManagedObject>("%K == %@", "key", value as AnyObject),
Where("%K == %@", "key", value.int64Value), Where<NSManagedObject>("%K == %@", "key", value.int64Value),
Where("key", isEqualTo: value), Where<NSManagedObject>("key", isEqualTo: value),
Where("key", isEqualTo: value.int64Value) Where<NSManagedObject>("key", isEqualTo: value.int64Value)
) )
} }
do { do {
let value: String = "value" let value: String = "value"
XCTAssertAllEqual( XCTAssertAllEqual(
Where("%K == %s", "key", value), Where<NSManagedObject>("%K == %s", "key", value),
Where("%K == %s", "key", value as AnyObject), Where<NSManagedObject>("%K == %s", "key", value as AnyObject),
Where("%K == %s", "key", NSString(string: value)), Where<NSManagedObject>("%K == %s", "key", NSString(string: value)),
Where("%K == %@", "key", value), Where<NSManagedObject>("%K == %@", "key", value),
Where("%K == %@", "key", value as AnyObject), Where<NSManagedObject>("%K == %@", "key", value as AnyObject),
Where("%K == %@", "key", NSString(string: value)), Where<NSManagedObject>("%K == %@", "key", NSString(string: value)),
Where("key", isEqualTo: value), Where<NSManagedObject>("key", isEqualTo: value),
Where("key", isEqualTo: value as NSString), Where<NSManagedObject>("key", isEqualTo: value as NSString),
Where("key", isEqualTo: NSString(string: value)) Where<NSManagedObject>("key", isEqualTo: NSString(string: value))
) )
} }
do { do {
let value = NSString(string: "value") let value = NSString(string: "value")
XCTAssertAllEqual( XCTAssertAllEqual(
Where("%K == %s", "key", value), Where<NSManagedObject>("%K == %s", "key", value),
Where("%K == %s", "key", value as String), Where<NSManagedObject>("%K == %s", "key", value as String),
Where("%K == %s", "key", value as String as AnyObject), Where<NSManagedObject>("%K == %s", "key", value as String as AnyObject),
Where("%K == %@", "key", value), Where<NSManagedObject>("%K == %@", "key", value),
Where("%K == %@", "key", value as String), Where<NSManagedObject>("%K == %@", "key", value as String),
Where("%K == %@", "key", value as String as AnyObject), Where<NSManagedObject>("%K == %@", "key", value as String as AnyObject),
Where("key", isEqualTo: value), Where<NSManagedObject>("key", isEqualTo: value),
Where("key", isEqualTo: value as String), Where<NSManagedObject>("key", isEqualTo: value as String),
Where("key", isEqualTo: value as String as NSString) Where<NSManagedObject>("key", isEqualTo: value as String as NSString)
) )
} }
do { do {
let value: [Int] = [100, 200] let value: [Int] = [100, 200]
XCTAssertAllEqual( XCTAssertAllEqual(
Where("%K IN %@", "key", value), Where<NSManagedObject>("%K IN %@", "key", value),
Where("%K IN %@", "key", value as AnyObject), Where<NSManagedObject>("%K IN %@", "key", value as AnyObject),
Where("%K IN %@", "key", value as [AnyObject]), Where<NSManagedObject>("%K IN %@", "key", value as [AnyObject]),
Where("%K IN %@", "key", value as NSArray), Where<NSManagedObject>("%K IN %@", "key", value as NSArray),
Where("%K IN %@", "key", NSArray(array: value)), Where<NSManagedObject>("%K IN %@", "key", NSArray(array: value)),
Where("%K IN %@", "key", value as AnyObject as! NSArray), Where<NSManagedObject>("%K IN %@", "key", value as AnyObject as! NSArray),
Where("key", isMemberOf: value) Where<NSManagedObject>("key", isMemberOf: value)
) )
} }
do { do {
let value: [Int64] = [Int64.min, 100, Int64.max] let value: [Int64] = [Int64.min, 100, Int64.max]
XCTAssertAllEqual( XCTAssertAllEqual(
Where("%K IN %@", "key", value), Where<NSManagedObject>("%K IN %@", "key", value),
Where("%K IN %@", "key", value as AnyObject), Where<NSManagedObject>("%K IN %@", "key", value as AnyObject),
Where("%K IN %@", "key", value as [AnyObject]), Where<NSManagedObject>("%K IN %@", "key", value as [AnyObject]),
Where("%K IN %@", "key", value as NSArray), Where<NSManagedObject>("%K IN %@", "key", value as NSArray),
Where("%K IN %@", "key", NSArray(array: value)), Where<NSManagedObject>("%K IN %@", "key", NSArray(array: value)),
Where("%K IN %@", "key", value as AnyObject as! NSArray), Where<NSManagedObject>("%K IN %@", "key", value as AnyObject as! NSArray),
Where("key", isMemberOf: value) Where<NSManagedObject>("key", isMemberOf: value)
) )
} }
} }
@@ -226,9 +226,9 @@ final class WhereTests: XCTestCase {
@objc @objc
dynamic func test_ThatWhereClauseOperations_ComputeCorrectly() { dynamic func test_ThatWhereClauseOperations_ComputeCorrectly() {
let whereClause1 = Where("key1", isEqualTo: "value1") let whereClause1 = Where<NSManagedObject>("key1", isEqualTo: "value1")
let whereClause2 = Where("key2", isEqualTo: "value2") let whereClause2 = Where<NSManagedObject>("key2", isEqualTo: "value2")
let whereClause3 = Where("key3", isEqualTo: "value3") let whereClause3 = Where<NSManagedObject>("key3", isEqualTo: "value3")
do { do {
@@ -259,8 +259,8 @@ final class WhereTests: XCTestCase {
do { do {
let andWhere = whereClause1 && whereClause2 && whereClause3 let andWhere = whereClause1 && whereClause2 && whereClause3
let noneWhere: Where? = nil let noneWhere: Where<NSManagedObject>? = nil
let someWhere: Where? = Where("key4", isEqualTo: "value4") let someWhere: Where<NSManagedObject>? = Where<NSManagedObject>("key4", isEqualTo: "value4")
let finalNoneWhere = andWhere && noneWhere let finalNoneWhere = andWhere && noneWhere
@@ -290,8 +290,8 @@ final class WhereTests: XCTestCase {
do { do {
let orWhere = whereClause1 || whereClause2 || whereClause3 let orWhere = whereClause1 || whereClause2 || whereClause3
let noneWhere: Where? = nil let noneWhere: Where<NSManagedObject>? = nil
let someWhere: Where? = Where("key4", isEqualTo: "value4") let someWhere: Where<NSManagedObject>? = Where<NSManagedObject>("key4", isEqualTo: "value4")
let finalNoneWhere = orWhere && noneWhere let finalNoneWhere = orWhere && noneWhere
@@ -307,7 +307,7 @@ final class WhereTests: XCTestCase {
@objc @objc
dynamic func test_ThatWhereClauses_ApplyToFetchRequestsCorrectly() { dynamic func test_ThatWhereClauses_ApplyToFetchRequestsCorrectly() {
let whereClause = Where("key", isEqualTo: "value") let whereClause = Where<NSManagedObject>("key", isEqualTo: "value")
let request = CoreStoreFetchRequest() let request = CoreStoreFetchRequest()
whereClause.applyToFetchRequest(request) whereClause.applyToFetchRequest(request)
XCTAssertNotNil(request.predicate) XCTAssertNotNil(request.predicate)

View File

@@ -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 - 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. - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
*/ */
public override func create<T>(_ into: Into<T>) -> T { public override func create<D>(_ into: Into<D>) -> D {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,
@@ -116,7 +116,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited - parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/ */
public override func edit<T: DynamicObject>(_ object: T?) -> T? { public override func edit<D: DynamicObject>(_ object: D?) -> D? {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,
@@ -133,7 +133,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter objectID: the `NSManagedObjectID` for the object to be edited - parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/ */
public override func edit<T>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? { public override func edit<D>(_ into: Into<D>, _ objectID: NSManagedObjectID) -> D? {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,
@@ -148,7 +148,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be deleted - parameter object: the `NSManagedObject` or `CoreStoreObject` to be deleted
*/ */
public override func delete<T: DynamicObject>(_ object: T?) { public override func delete<D: DynamicObject>(_ object: D?) {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,
@@ -165,7 +165,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter object2: another `DynamicObject` to be deleted - parameter object2: another `DynamicObject` to be deleted
- parameter objects: other `DynamicObject`s to be deleted - parameter objects: other `DynamicObject`s to be deleted
*/ */
public override func delete<T: DynamicObject>(_ object1: T?, _ object2: T?, _ objects: T?...) { public override func delete<D: DynamicObject>(_ object1: D?, _ object2: D?, _ objects: D?...) {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,

View File

@@ -39,9 +39,9 @@ public extension BaseDataTransaction {
- throws: an `Error` thrown from any of the `ImportableObject` methods - throws: an `Error` thrown from any of the `ImportableObject` methods
- returns: the created `ImportableObject` instance, or `nil` if the import was ignored - returns: the created `ImportableObject` instance, or `nil` if the import was ignored
*/ */
public func importObject<T: DynamicObject & ImportableObject>( public func importObject<D: ImportableObject>(
_ into: Into<T>, _ into: Into<D>,
source: T.ImportSource) throws -> T? { source: D.ImportSource) throws -> D? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -69,9 +69,9 @@ public extension BaseDataTransaction {
- parameter source: the object to import values from - parameter source: the object to import values from
- throws: an `Error` thrown from any of the `ImportableObject` methods - throws: an `Error` thrown from any of the `ImportableObject` methods
*/ */
public func importObject<T: DynamicObject & ImportableObject>( public func importObject<D: ImportableObject>(
_ object: T, _ object: D,
source: T.ImportSource) throws { source: D.ImportSource) throws {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -97,9 +97,9 @@ public extension BaseDataTransaction {
- throws: an `Error` thrown from any of the `ImportableObject` methods - throws: an `Error` thrown from any of the `ImportableObject` methods
- returns: the array of created `ImportableObject` instances - returns: the array of created `ImportableObject` instances
*/ */
public func importObjects<T: DynamicObject & ImportableObject, S: Sequence>( public func importObjects<D: ImportableObject, S: Sequence>(
_ into: Into<T>, _ into: Into<D>,
sourceArray: S) throws -> [T] where S.Iterator.Element == T.ImportSource { sourceArray: S) throws -> [D] where S.Iterator.Element == D.ImportSource {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -108,7 +108,7 @@ public extension BaseDataTransaction {
return try autoreleasepool { return try autoreleasepool {
return try sourceArray.flatMap { (source) -> T? in return try sourceArray.flatMap { (source) -> D? in
let entityType = into.entityClass let entityType = into.entityClass
guard entityType.shouldInsert(from: source, in: self) else { 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 - throws: an `Error` thrown from any of the `ImportableUniqueObject` methods
- returns: the created/updated `ImportableUniqueObject` instance, or `nil` if the import was ignored - returns: the created/updated `ImportableUniqueObject` instance, or `nil` if the import was ignored
*/ */
public func importUniqueObject<T: DynamicObject & ImportableUniqueObject>( public func importUniqueObject<D: ImportableUniqueObject>(
_ into: Into<T>, _ into: Into<D>,
source: T.ImportSource) throws -> T? { source: D.ImportSource) throws -> D? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -151,7 +151,7 @@ public extension BaseDataTransaction {
return nil return nil
} }
if let object = self.fetchOne(From(entityType), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) { if let object = self.fetchOne(From(entityType), Where<D>(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) {
guard entityType.shouldUpdate(from: source, in: self) else { 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 - throws: an `Error` thrown from any of the `ImportableUniqueObject` methods
- returns: the array of created/updated `ImportableUniqueObject` instances - returns: the array of created/updated `ImportableUniqueObject` instances
*/ */
public func importUniqueObjects<T: DynamicObject & ImportableUniqueObject, S: Sequence>( public func importUniqueObjects<D: ImportableUniqueObject, S: Sequence>(
_ into: Into<T>, _ into: Into<D>,
sourceArray: S, 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( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -198,10 +198,10 @@ public extension BaseDataTransaction {
return try autoreleasepool { return try autoreleasepool {
let entityType = into.entityClass let entityType = into.entityClass
var importSourceByID = Dictionary<T.UniqueIDType, T.ImportSource>() var importSourceByID = Dictionary<D.UniqueIDType, D.ImportSource>()
let sortedIDs = try autoreleasepool { 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 { guard let uniqueIDValue = try entityType.uniqueID(from: source, in: self) else {
@@ -214,12 +214,12 @@ public extension BaseDataTransaction {
importSourceByID = try autoreleasepool { try preProcess(importSourceByID) } importSourceByID = try autoreleasepool { try preProcess(importSourceByID) }
var existingObjectsByID = Dictionary<T.UniqueIDType, T>() var existingObjectsByID = Dictionary<D.UniqueIDType, D>()
self.fetchAll(From(entityType), Where(entityType.uniqueIDKeyPath, isMemberOf: sortedIDs))? self.fetchAll(From(entityType), Where<D>(entityType.uniqueIDKeyPath, isMemberOf: sortedIDs))?
.forEach { existingObjectsByID[$0.uniqueIDValue] = $0 } .forEach { existingObjectsByID[$0.uniqueIDValue] = $0 }
var processedObjectIDs = Set<T.UniqueIDType>() var processedObjectIDs = Set<D.UniqueIDType>()
var result = [T]() var result = [D]()
for objectID in sortedIDs where !processedObjectIDs.contains(objectID) { for objectID in sortedIDs where !processedObjectIDs.contains(objectID) {

View File

@@ -39,13 +39,12 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
- returns: the number of `DynamicObject`s deleted - returns: the number of `DynamicObject`s deleted
*/ */
@discardableResult @discardableResult
public func deleteAll<T>(_ from: From<T>, _ deleteClauses: DeleteClause...) -> Int? { public func deleteAll<D>(_ from: From<D>, _ deleteClauses: DeleteClause...) -> Int? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
"Attempted to delete from a \(cs_typeName(self)) outside its designated queue." "Attempted to delete from a \(cs_typeName(self)) outside its designated queue."
) )
return self.context.deleteAll(from, deleteClauses) return self.context.deleteAll(from, deleteClauses)
} }
@@ -57,14 +56,32 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
- returns: the number of `DynamicObject`s deleted - returns: the number of `DynamicObject`s deleted
*/ */
@discardableResult @discardableResult
public func deleteAll<T>(_ from: From<T>, _ deleteClauses: [DeleteClause]) -> Int? { public func deleteAll<D>(_ from: From<D>, _ 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<Person>().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<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
"Attempted to delete from a \(cs_typeName(self)) outside its designated queue." "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 - 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. - returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found.
*/ */
public func fetchExisting<T: DynamicObject>(_ object: T) -> T? { public func fetchExisting<D: DynamicObject>(_ object: D) -> D? {
return self.context.fetchExisting(object) return self.context.fetchExisting(object)
} }
@@ -87,7 +104,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
- parameter objectID: the `NSManagedObjectID` for the object - parameter objectID: the `NSManagedObjectID` for the object
- returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found. - returns: the `DynamicObject` instance if the object exists in the transaction, or `nil` if not found.
*/ */
public func fetchExisting<T: DynamicObject>(_ objectID: NSManagedObjectID) -> T? { public func fetchExisting<D: DynamicObject>(_ objectID: NSManagedObjectID) -> D? {
return self.context.fetchExisting(objectID) 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 - parameter objects: an array of `DynamicObject`s created/fetched outside the transaction
- returns: the `DynamicObject` array for objects that exists in the transaction - returns: the `DynamicObject` array for objects that exists in the transaction
*/ */
public func fetchExisting<T: DynamicObject, S: Sequence>(_ objects: S) -> [T] where S.Iterator.Element == T { public func fetchExisting<D: DynamicObject, S: Sequence>(_ objects: S) -> [D] where S.Iterator.Element == D {
return self.context.fetchExisting(objects) return self.context.fetchExisting(objects)
} }
@@ -109,7 +126,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
- parameter objectIDs: the `NSManagedObjectID` array for the objects - parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `DynamicObject` array for objects that exists in the transaction - returns: the `DynamicObject` array for objects that exists in the transaction
*/ */
public func fetchExisting<T: DynamicObject, S: Sequence>(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { public func fetchExisting<D: DynamicObject, S: Sequence>(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID {
return self.context.fetchExisting(objectIDs) 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. - 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 - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
*/ */
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? { public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), 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. - 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 - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
*/ */
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? { public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -146,6 +163,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchOne(from, fetchClauses) return self.context.fetchOne(from, fetchClauses)
} }
// TODO: docs
public func fetchOne<B: FetchChainableBuilderType>(_ 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. 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. - 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 - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
*/ */
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? { public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), 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. - 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 - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
*/ */
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? { public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -178,6 +205,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchAll(from, fetchClauses) return self.context.fetchAll(from, fetchClauses)
} }
// TODO: docs
public func fetchAll<B: FetchChainableBuilderType>(_ 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. 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. - 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 - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? { public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), 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. - 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 - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? { public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -210,6 +247,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchCount(from, fetchClauses) return self.context.fetchCount(from, fetchClauses)
} }
// TODO: docs
public func fetchCount<B: FetchChainableBuilderType>(_ 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. 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. - 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 - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
*/ */
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { public func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), 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. - 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 - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
*/ */
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { public func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -242,6 +289,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchObjectID(from, fetchClauses) return self.context.fetchObjectID(from, fetchClauses)
} }
// TODO: docs
public func fetchObjectID<B: FetchChainableBuilderType>(_ 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. 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. - 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 - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { public func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), 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. - 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 - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { public func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -274,6 +331,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchObjectIDs(from, fetchClauses) return self.context.fetchObjectIDs(from, fetchClauses)
} }
// TODO: docs
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ 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 // 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),

View File

@@ -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 - 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. - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
*/ */
public func create<T>(_ into: Into<T>) -> T { public func create<D>(_ into: Into<D>) -> D {
let entityClass = into.entityClass let entityClass = into.entityClass
CoreStore.assert( CoreStore.assert(
@@ -121,7 +121,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter object: the `NSManagedObject` type to be edited - parameter object: the `NSManagedObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject`. - returns: an editable proxy for the specified `NSManagedObject`.
*/ */
public func edit<T: DynamicObject>(_ object: T?) -> T? { public func edit<D: DynamicObject>(_ object: D?) -> D? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -141,7 +141,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter objectID: the `NSManagedObjectID` for the object to be edited - parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject`. - returns: an editable proxy for the specified `NSManagedObject`.
*/ */
public func edit<T>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? { public func edit<D>(_ into: Into<D>, _ objectID: NSManagedObjectID) -> D? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -160,7 +160,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter object: the `NSManagedObject` to be deleted - parameter object: the `NSManagedObject` to be deleted
*/ */
public func delete<T: DynamicObject>(_ object: T?) { public func delete<D: DynamicObject>(_ object: D?) {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -179,7 +179,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter object2: another `NSManagedObject` to be deleted - parameter object2: another `NSManagedObject` to be deleted
- parameter objects: other `NSManagedObject`s to be deleted - parameter objects: other `NSManagedObject`s to be deleted
*/ */
public func delete<T: DynamicObject>(_ object1: T?, _ object2: T?, _ objects: T?...) { public func delete<D: DynamicObject>(_ object1: D?, _ object2: D?, _ objects: D?...) {
self.delete(([object1, object2] + objects).flatMap { $0 }) self.delete(([object1, object2] + objects).flatMap { $0 })
} }
@@ -220,7 +220,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `DynamicObject` subclass to filter - parameter entity: the `DynamicObject` subclass to filter
- returns: a `Set` of pending `DynamicObject`s of the specified type that were inserted to the transaction. - returns: a `Set` of pending `DynamicObject`s of the specified type that were inserted to the transaction.
*/ */
public func insertedObjects<T: DynamicObject>(_ entity: T.Type) -> Set<T> { public func insertedObjects<D: DynamicObject>(_ entity: D.Type) -> Set<D> {
CoreStore.assert( CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(), self.transactionQueue.cs_isCurrentExecutionContext(),
@@ -257,7 +257,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `DynamicObject` subclass to filter - parameter entity: the `DynamicObject` subclass to filter
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction. - returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction.
*/ */
public func insertedObjectIDs<T: DynamicObject>(_ entity: T.Type) -> Set<NSManagedObjectID> { public func insertedObjectIDs<D: DynamicObject>(_ entity: D.Type) -> Set<NSManagedObjectID> {
CoreStore.assert( CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(), self.transactionQueue.cs_isCurrentExecutionContext(),
@@ -276,7 +276,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `DynamicObject` subclass to filter - parameter entity: the `DynamicObject` subclass to filter
- returns: a `Set` of pending `DynamicObject`s of the specified type that were updated in the transaction. - returns: a `Set` of pending `DynamicObject`s of the specified type that were updated in the transaction.
*/ */
public func updatedObjects<T: DynamicObject>(_ entity: T.Type) -> Set<T> { public func updatedObjects<D: DynamicObject>(_ entity: D.Type) -> Set<D> {
CoreStore.assert( CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(), self.transactionQueue.cs_isCurrentExecutionContext(),
@@ -313,7 +313,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `DynamicObject` subclass to filter - parameter entity: the `DynamicObject` subclass to filter
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction. - returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction.
*/ */
public func updatedObjectIDs<T: DynamicObject>(_ entity: T.Type) -> Set<NSManagedObjectID> { public func updatedObjectIDs<D: DynamicObject>(_ entity: D.Type) -> Set<NSManagedObjectID> {
CoreStore.assert( CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(), self.transactionQueue.cs_isCurrentExecutionContext(),
@@ -332,7 +332,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `DynamicObject` subclass to filter - parameter entity: the `DynamicObject` subclass to filter
- returns: a `Set` of pending `DynamicObject`s of the specified type that were deleted from the transaction. - returns: a `Set` of pending `DynamicObject`s of the specified type that were deleted from the transaction.
*/ */
public func deletedObjects<T: DynamicObject>(_ entity: T.Type) -> Set<T> { public func deletedObjects<D: DynamicObject>(_ entity: D.Type) -> Set<D> {
CoreStore.assert( CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(), self.transactionQueue.cs_isCurrentExecutionContext(),
@@ -370,7 +370,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `DynamicObject` subclass to filter - parameter entity: the `DynamicObject` subclass to filter
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction. - returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
*/ */
public func deletedObjectIDs<T: DynamicObject>(_ entity: T.Type) -> Set<NSManagedObjectID> { public func deletedObjectIDs<D: DynamicObject>(_ entity: D.Type) -> Set<NSManagedObjectID> {
CoreStore.assert( CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(), self.transactionQueue.cs_isCurrentExecutionContext(),

View File

@@ -145,7 +145,7 @@ public final class CSFrom: NSObject {
public let bridgeToSwift: From<NSManagedObject> public let bridgeToSwift: From<NSManagedObject>
public init<T: NSManagedObject>(_ swiftValue: From<T>) { public init<D: NSManagedObject>(_ swiftValue: From<D>) {
self.bridgeToSwift = swiftValue.downcast() self.bridgeToSwift = swiftValue.downcast()
super.init() super.init()
@@ -155,7 +155,7 @@ public final class CSFrom: NSObject {
// MARK: - From // MARK: - From
extension From where T: NSManagedObject { extension From where D: NSManagedObject {
// MARK: CoreStoreSwiftType // MARK: CoreStoreSwiftType

View File

@@ -112,7 +112,7 @@ public final class CSInto: NSObject {
public let bridgeToSwift: Into<NSManagedObject> public let bridgeToSwift: Into<NSManagedObject>
public required init<T: NSManagedObject>(_ swiftValue: Into<T>) { public required init<D: NSManagedObject>(_ swiftValue: Into<D>) {
self.bridgeToSwift = swiftValue.downcast() self.bridgeToSwift = swiftValue.downcast()
super.init() super.init()
@@ -122,7 +122,7 @@ public final class CSInto: NSObject {
// MARK: - Into // MARK: - Into
extension Into where T: NSManagedObject { extension Into where D: NSManagedObject {
// MARK: CoreStoreSwiftType // MARK: CoreStoreSwiftType

View File

@@ -35,7 +35,7 @@ import CoreData
- SeeAlso: `OrderBy` - SeeAlso: `OrderBy`
*/ */
@objc @objc
public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType { public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause {
/** /**
The list of sort descriptors The list of sort descriptors
@@ -110,11 +110,11 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl
// MARK: CoreStoreObjectiveCType // MARK: CoreStoreObjectiveCType
public let bridgeToSwift: OrderBy public let bridgeToSwift: OrderBy<NSManagedObject>
public init(_ swiftValue: OrderBy) { public init<D: NSManagedObject>(_ swiftValue: OrderBy<D>) {
self.bridgeToSwift = swiftValue self.bridgeToSwift = swiftValue.downcast()
super.init() super.init()
} }
} }
@@ -122,7 +122,7 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl
// MARK: - OrderBy // MARK: - OrderBy
extension OrderBy: CoreStoreSwiftType { extension OrderBy where D: NSManagedObject {
// MARK: CoreStoreSwiftType // MARK: CoreStoreSwiftType
@@ -130,4 +130,12 @@ extension OrderBy: CoreStoreSwiftType {
return CSOrderBy(self) return CSOrderBy(self)
} }
// MARK: FilePrivate
fileprivate func downcast() -> OrderBy<NSManagedObject> {
return OrderBy<NSManagedObject>(self.sortDescriptors)
}
} }

View File

@@ -35,7 +35,7 @@ import CoreData
- SeeAlso: `Where` - SeeAlso: `Where`
*/ */
@objc @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 The internal `NSPredicate` instance for the `Where` clause
@@ -149,11 +149,11 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
// MARK: CoreStoreObjectiveCType // MARK: CoreStoreObjectiveCType
public let bridgeToSwift: Where public let bridgeToSwift: Where<NSManagedObject>
public init(_ swiftValue: Where) { public init<D: NSManagedObject>(_ swiftValue: Where<D>) {
self.bridgeToSwift = swiftValue self.bridgeToSwift = swiftValue.downcast()
super.init() super.init()
} }
} }
@@ -161,7 +161,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
// MARK: - Where // MARK: - Where
extension Where: CoreStoreSwiftType { extension Where where D: NSManagedObject {
// MARK: CoreStoreSwiftType // MARK: CoreStoreSwiftType
@@ -169,4 +169,12 @@ extension Where: CoreStoreSwiftType {
return CSWhere(self) return CSWhere(self)
} }
// MARK: FilePrivate
fileprivate func downcast() -> Where<NSManagedObject> {
return Where<NSManagedObject>(self.predicate)
}
} }

View File

@@ -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<ObjectType> { get set }
var fetchClauses: [FetchClause] { get set }
}
public protocol QueryChainableBuilderType {
associatedtype ObjectType: DynamicObject
associatedtype ResultType: SelectResultType
var from: From<ObjectType> { get set }
var select: Select<ResultType> { get set }
var groupBy: GroupBy { get set }
var fetchClauses: [FetchClause] { get set }
}
public protocol SectionMonitorBuilderType {
associatedtype ObjectType: DynamicObject
var from: From<ObjectType> { get set }
var sectionBy: SectionBy { get set }
var fetchClauses: [FetchClause] { get set }
}
// MARK: - FetchChainBuilder
public struct FetchChainBuilder<D: DynamicObject>: FetchChainableBuilderType {
// MARK: FetchChainableBuilderType
public typealias ObjectType = D
public var from: From<D>
public var fetchClauses: [FetchClause] = []
}
// MARK: - QueryChainBuilder
public struct QueryChainBuilder<D: DynamicObject, R: SelectResultType>: QueryChainableBuilderType {
// MARK: QueryChainableBuilderType
public typealias ObjectType = D
public typealias ResultType = R
public var from: From<D>
public var select: Select<R>
public var groupBy: GroupBy
public var fetchClauses: [FetchClause] = []
}
// MARK: - SectionMonitorChainBuilder
public struct SectionMonitorChainBuilder<D: DynamicObject>: SectionMonitorBuilderType {
// MARK: SectionMonitorBuilderType
public var from: From<D>
public var sectionBy: SectionBy
public var fetchClauses: [FetchClause] = []
}
// MARK: - From
public extension From {
public func select<R>(_ resultType: R.Type, _ selectTerm: SelectTerm, _ selectTerms: SelectTerm...) -> QueryChainBuilder<D, R> {
return self.select(resultType, [selectTerm] + selectTerms)
}
public func select<R>(_ resultType: R.Type, _ selectTerms: [SelectTerm]) -> QueryChainBuilder<D, R> {
return .init(
from: self,
select: .init(selectTerms),
groupBy: .init(),
fetchClauses: []
)
}
public func sectionBy(_ sectionKeyPath: KeyPathString) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(sectionKeyPath, { $0 })
}
public func sectionBy(_ sectionKeyPath: KeyPathString, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> {
return .init(
from: self,
sectionBy: .init(sectionKeyPath, sectionIndexTransformer),
fetchClauses: []
)
}
public func `where`(_ clause: Where<D>) -> FetchChainBuilder<D> {
return self.fetchChain(appending: clause)
}
public func `where`(format: String, _ args: Any...) -> FetchChainBuilder<D> {
return self.fetchChain(appending: Where<D>(format, argumentArray: args))
}
public func `where`(format: String, argumentArray: [Any]?) -> FetchChainBuilder<D> {
return self.fetchChain(appending: Where<D>(format, argumentArray: argumentArray))
}
public func orderBy(_ sortKey: OrderBy<D>.SortKey, _ sortKeys: OrderBy<D>.SortKey...) -> FetchChainBuilder<D> {
return self.fetchChain(appending: OrderBy<D>([sortKey] + sortKeys))
}
public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> FetchChainBuilder<D> {
return self.fetchChain(appending: Tweak(fetchRequest))
}
public func appending(_ clause: FetchClause) -> FetchChainBuilder<D> {
return self.fetchChain(appending: clause)
}
// MARK: Private
private func fetchChain(appending clause: FetchClause) -> FetchChainBuilder<D> {
return .init(from: self, fetchClauses: [clause])
}
}
public extension FetchChainBuilder {
public func `where`(_ clause: Where<D>) -> FetchChainBuilder<D> {
return self.fetchChain(appending: clause)
}
public func `where`(format: String, _ args: Any...) -> FetchChainBuilder<D> {
return self.fetchChain(appending: Where<D>(format, argumentArray: args))
}
public func `where`(format: String, argumentArray: [Any]?) -> FetchChainBuilder<D> {
return self.fetchChain(appending: Where<D>(format, argumentArray: argumentArray))
}
public func orderBy(_ sortKey: OrderBy<D>.SortKey, _ sortKeys: OrderBy<D>.SortKey...) -> FetchChainBuilder<D> {
return self.fetchChain(appending: OrderBy<D>([sortKey] + sortKeys))
}
public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> FetchChainBuilder<D> {
return self.fetchChain(appending: Tweak(fetchRequest))
}
public func appending(_ clause: FetchClause) -> FetchChainBuilder<D> {
return self.fetchChain(appending: clause)
}
// MARK: Private
private func fetchChain(appending clause: FetchClause) -> FetchChainBuilder<D> {
return .init(
from: self.from,
fetchClauses: self.fetchClauses + [clause]
)
}
}
public extension QueryChainBuilder {
public func groupBy(_ keyPath: KeyPathString, _ keyPaths: KeyPathString...) -> QueryChainBuilder<D, R> {
return self.groupBy([keyPath] + keyPaths)
}
public func groupBy(_ keyPaths: [KeyPathString]) -> QueryChainBuilder<D, R> {
return .init(
from: self.from,
select: self.select,
groupBy: .init(keyPaths),
fetchClauses: self.fetchClauses
)
}
public func `where`(_ clause: Where<D>) -> QueryChainBuilder<D, R> {
return self.queryChain(appending: clause)
}
public func `where`(format: String, _ args: Any...) -> QueryChainBuilder<D, R> {
return self.queryChain(appending: Where<D>(format, argumentArray: args))
}
public func `where`(format: String, argumentArray: [Any]?) -> QueryChainBuilder<D, R> {
return self.queryChain(appending: Where<D>(format, argumentArray: argumentArray))
}
public func orderBy(_ sortKey: OrderBy<D>.SortKey, _ sortKeys: OrderBy<D>.SortKey...) -> QueryChainBuilder<D, R> {
return self.queryChain(appending: OrderBy<D>([sortKey] + sortKeys))
}
public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> QueryChainBuilder<D, R> {
return self.queryChain(appending: Tweak(fetchRequest))
}
public func appending(_ clause: FetchClause) -> QueryChainBuilder<D, R> {
return self.queryChain(appending: clause)
}
// MARK: Private
private func queryChain(appending clause: FetchClause) -> QueryChainBuilder<D, R> {
return .init(
from: self.from,
select: self.select,
groupBy: self.groupBy,
fetchClauses: self.fetchClauses + [clause]
)
}
}
public extension SectionMonitorChainBuilder {
public func `where`(_ clause: Where<D>) -> SectionMonitorChainBuilder<D> {
return self.sectionMonitorChain(appending: clause)
}
public func `where`(format: String, _ args: Any...) -> SectionMonitorChainBuilder<D> {
return self.sectionMonitorChain(appending: Where<D>(format, argumentArray: args))
}
public func `where`(format: String, argumentArray: [Any]?) -> SectionMonitorChainBuilder<D> {
return self.sectionMonitorChain(appending: Where<D>(format, argumentArray: argumentArray))
}
public func orderBy(_ sortKey: OrderBy<D>.SortKey, _ sortKeys: OrderBy<D>.SortKey...) -> SectionMonitorChainBuilder<D> {
return self.sectionMonitorChain(appending: OrderBy<D>([sortKey] + sortKeys))
}
public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> SectionMonitorChainBuilder<D> {
return self.sectionMonitorChain(appending: Tweak(fetchRequest))
}
public func appending(_ clause: FetchClause) -> SectionMonitorChainBuilder<D> {
return self.sectionMonitorChain(appending: clause)
}
// MARK: Private
private func sectionMonitorChain(appending clause: FetchClause) -> SectionMonitorChainBuilder<D> {
return .init(
from: self.from,
sectionBy: self.sectionBy,
fetchClauses: self.fetchClauses + [clause]
)
}
}

View File

@@ -43,7 +43,7 @@ public protocol FetchClause {
/** /**
The `QueryClause` implement clauses used to configure `NSFetchRequest`s. The `QueryClause` implement clauses used to configure `NSFetchRequest`s.
*/ */
public protocol QueryClause { public protocol QueryClause: FetchClause {
func applyToFetchRequest<T>(_ fetchRequest: NSFetchRequest<T>) func applyToFetchRequest<T>(_ fetchRequest: NSFetchRequest<T>)
} }
@@ -54,7 +54,7 @@ public protocol QueryClause {
/** /**
The `DeleteClause` implement clauses used to configure `NSFetchRequest`s. The `DeleteClause` implement clauses used to configure `NSFetchRequest`s.
*/ */
public protocol DeleteClause { public protocol DeleteClause: FetchClause {
func applyToFetchRequest<T>(_ fetchRequest: NSFetchRequest<T>) func applyToFetchRequest<T>(_ fetchRequest: NSFetchRequest<T>)
} }

View File

@@ -38,7 +38,7 @@ public extension CoreStore {
- parameter object: the `DynamicObject` to observe changes from - parameter object: the `DynamicObject` to observe changes from
- returns: a `ObjectMonitor` that monitors changes to `object` - returns: a `ObjectMonitor` that monitors changes to `object`
*/ */
public static func monitorObject<T>(_ object: T) -> ObjectMonitor<T> { public static func monitorObject<D>(_ object: D) -> ObjectMonitor<D> {
return self.defaultStack.monitorObject(object) 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public static func monitorList<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> { public static func monitorList<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> ListMonitor<D> {
return self.defaultStack.monitorList(from, fetchClauses) 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public static func monitorList<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> { public static func monitorList<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
return self.defaultStack.monitorList(from, fetchClauses) return self.defaultStack.monitorList(from, fetchClauses)
} }
@@ -74,7 +74,7 @@ public extension CoreStore {
- parameter from: a `From` clause indicating the entity type - 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public static func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) { public static func monitorList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ fetchClauses: FetchClause...) {
self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
} }
@@ -86,7 +86,7 @@ public extension CoreStore {
- parameter from: a `From` clause indicating the entity type - 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public static func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) { public static func monitorList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ fetchClauses: [FetchClause]) {
self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public static func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> { public static func monitorSectionedList<D>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<D> {
return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public static func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> { public static func monitorSectionedList<D>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) 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 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public static func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { public static func monitorSectionedList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) 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 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public static func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { public static func monitorSectionedList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses)
} }

View File

@@ -37,7 +37,7 @@ public extension CoreStore {
- parameter object: a reference to the object created/fetched outside the `DataStack` - 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. - returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/ */
public static func fetchExisting<T: DynamicObject>(_ object: T) -> T? { public static func fetchExisting<D: DynamicObject>(_ object: D) -> D? {
return self.defaultStack.fetchExisting(object) return self.defaultStack.fetchExisting(object)
} }
@@ -48,7 +48,7 @@ public extension CoreStore {
- parameter objectID: the `NSManagedObjectID` for the object - parameter objectID: the `NSManagedObjectID` for the object
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found. - returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/ */
public static func fetchExisting<T: DynamicObject>(_ objectID: NSManagedObjectID) -> T? { public static func fetchExisting<D: DynamicObject>(_ objectID: NSManagedObjectID) -> D? {
return self.defaultStack.fetchExisting(objectID) return self.defaultStack.fetchExisting(objectID)
} }
@@ -59,7 +59,7 @@ public extension CoreStore {
- parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack` - parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack`
- returns: the `DynamicObject` array for objects that exists in the `DataStack` - returns: the `DynamicObject` array for objects that exists in the `DataStack`
*/ */
public static func fetchExisting<T: DynamicObject, S: Sequence>(_ objects: S) -> [T] where S.Iterator.Element == T { public static func fetchExisting<D: DynamicObject, S: Sequence>(_ objects: S) -> [D] where S.Iterator.Element == D {
return self.defaultStack.fetchExisting(objects) return self.defaultStack.fetchExisting(objects)
} }
@@ -70,7 +70,7 @@ public extension CoreStore {
- parameter objectIDs: the `NSManagedObjectID` array for the objects - parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `DynamicObject` array for objects that exists in the `DataStack` - returns: the `DynamicObject` array for objects that exists in the `DataStack`
*/ */
public static func fetchExisting<T: DynamicObject, S: Sequence>(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { public static func fetchExisting<D: DynamicObject, S: Sequence>(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID {
return self.defaultStack.fetchExisting(objectIDs) 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. - 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 - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
*/ */
public static func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? { public static func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D? {
return self.defaultStack.fetchOne(from, fetchClauses) 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. - 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 - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
*/ */
public static func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? { public static func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D? {
return self.defaultStack.fetchOne(from, fetchClauses) 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. - 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 - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
*/ */
public static func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? { public static func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]? {
return self.defaultStack.fetchAll(from, fetchClauses) 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. - 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 - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
*/ */
public static func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? { public static func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]? {
return self.defaultStack.fetchAll(from, fetchClauses) 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. - 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 - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public static func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? { public static func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int? {
return self.defaultStack.fetchCount(from, fetchClauses) 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. - 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 - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public static func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? { public static func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int? {
return self.defaultStack.fetchCount(from, fetchClauses) 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. - 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 - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
*/ */
public static func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { public static func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
return self.defaultStack.fetchObjectID(from, fetchClauses) 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. - 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 - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
*/ */
public static func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { public static func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
return self.defaultStack.fetchObjectID(from, fetchClauses) 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. - 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 - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public static func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { public static func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
return self.defaultStack.fetchObjectIDs(from, fetchClauses) 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. - 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 - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public static func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { public static func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
return self.defaultStack.fetchObjectIDs(from, fetchClauses) 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public static func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? { public static func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
return self.defaultStack.queryValue(from, selectClause, queryClauses) 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public static func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? { public static func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
return self.defaultStack.queryValue(from, selectClause, queryClauses) 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public static func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? { public static func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
return self.defaultStack.queryAttributes(from, selectClause, queryClauses) 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public static func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? { public static func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
return self.defaultStack.queryAttributes(from, selectClause, queryClauses) return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
} }

View File

@@ -35,7 +35,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
// MARK: Internal // MARK: Internal
@nonobjc @nonobjc
internal convenience init<T>(dataStack: DataStack, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) { internal convenience init<D>(dataStack: DataStack, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<D>, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
self.init( self.init(
context: dataStack.mainContext, context: dataStack.mainContext,
@@ -47,7 +47,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
} }
@nonobjc @nonobjc
internal init<T>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) { internal init<D>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<D>, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
_ = from.applyToFetchRequest( _ = from.applyToFetchRequest(
fetchRequest, fetchRequest,

View File

@@ -26,6 +26,58 @@
import CoreData import CoreData
import Foundation import Foundation
//public extension From where D: NSManagedObject {
//
//// public func select<R>(_ resultType: R.Type, _ selectTerm: SelectTerm, _ selectTerms: SelectTerm...) -> QueryChainBuilder<D, R> {
////
//// return self.select(resultType, [selectTerm] + selectTerms)
//// }
////
//// public func select<R>(_ resultType: R.Type, _ selectTerms: [SelectTerm]) -> QueryChainBuilder<D, R> {
////
//// return .init(
//// from: self,
//// select: .init(selectTerms),
//// groupBy: .init(),
//// fetchClauses: []
//// )
//// }
//
// public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, T>) -> SectionMonitorChainBuilder<D> {
//
// return self.sectionBy(sectionKeyPath._kvcKeyPathString!, { $0 })
// }
//
// public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, T>, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> {
//
// return self.sectionBy(sectionKeyPath._kvcKeyPathString!, sectionIndexTransformer)
// }
//
// public func `where`<T>(_ keyPath: KeyPath<D, T>, isEqualTo value: Void?) -> FetchChainBuilder<D> {
//
// return self.where(keyPath._kvcKeyPathString!, isEqualTo: value)
// }
//
// public func `where`<U: QueryableAttributeType>(_ keyPath: KeyPath<D, U>, isEqualTo value: U?) -> FetchChainBuilder<D> {
//
// return self.where(keyPath._kvcKeyPathString!, isEqualTo: value)
// }
//
// public func `where`(_ keyPath: KeyPath<D, D>, isEqualTo object: D?) -> FetchChainBuilder<D> {
//
// return self.where(keyPath._kvcKeyPathString!, isEqualTo: object)
// }
//
// public func `where`<S: Sequence>(_ keyPath: KeyPath<D, S.Iterator.Element>, isMemberOf list: S) -> FetchChainBuilder<D> where S.Iterator.Element: QueryableAttributeType {
//
// return self.where(keyPath._kvcKeyPathString!, isMemberOf: list)
// }
//
// public func `where`<S: Sequence>(_ keyPath: KeyPath<D, S.Iterator.Element>, isMemberOf list: S) -> FetchChainBuilder<D> where S.Iterator.Element == D {
//
// return self.where(keyPath._kvcKeyPathString!, isMemberOf: list)
// }
//}
// MARK: - DynamicObject // MARK: - DynamicObject
@@ -92,7 +144,7 @@ public extension DynamicObject where Self: CoreStoreObject {
let person = CoreStore.fetchOne(From<Person>(), Person.where { $0.nickname == "John" }) let person = CoreStore.fetchOne(From<Person>(), Person.where { $0.nickname == "John" })
``` ```
*/ */
public static func `where`(_ condition: (Self) -> Where) -> Where { public static func `where`(_ condition: (Self) -> Where<Self>) -> Where<Self> {
return condition(self.meta) return condition(self.meta)
} }
@@ -103,7 +155,7 @@ public extension DynamicObject where Self: CoreStoreObject {
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(ascending: { $0.age })) let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(ascending: { $0.age }))
``` ```
*/ */
public static func orderBy<O, V>(ascending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy { public static func orderBy<O, V>(ascending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy<Self> {
return OrderBy(.ascending(attribute(self.meta).keyPath)) return OrderBy(.ascending(attribute(self.meta).keyPath))
} }
@@ -114,7 +166,7 @@ public extension DynamicObject where Self: CoreStoreObject {
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(ascending: { $0.age })) let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(ascending: { $0.age }))
``` ```
*/ */
public static func orderBy<O, V>(ascending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy { public static func orderBy<O, V>(ascending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy<Self> {
return OrderBy(.ascending(attribute(self.meta).keyPath)) return OrderBy(.ascending(attribute(self.meta).keyPath))
} }
@@ -125,7 +177,7 @@ public extension DynamicObject where Self: CoreStoreObject {
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(descending: { $0.age })) let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(descending: { $0.age }))
``` ```
*/ */
public static func orderBy<O, V>(descending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy { public static func orderBy<O, V>(descending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy<Self> {
return OrderBy(.descending(attribute(self.meta).keyPath)) return OrderBy(.descending(attribute(self.meta).keyPath))
} }
@@ -136,22 +188,7 @@ public extension DynamicObject where Self: CoreStoreObject {
let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(descending: { $0.age })) let person = CoreStore.fetchAll(From<Person>(), Person.orderBy(descending: { $0.age }))
``` ```
*/ */
public static func orderBy<O, V>(descending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy { public static func orderBy<O, V>(descending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy<Self> {
return OrderBy(.descending(attribute(self.meta).keyPath))
}
// MARK: Deprecated
@available(*, deprecated, renamed: "orderBy(ascending:)")
public static func ascending<O, V>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
return OrderBy(.ascending(attribute(self.meta).keyPath))
}
@available(*, deprecated, renamed: "orderBy(descending:)")
public static func descending<O, V>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy {
return OrderBy(.descending(attribute(self.meta).keyPath)) return OrderBy(.descending(attribute(self.meta).keyPath))
} }
@@ -169,7 +206,7 @@ public extension ValueContainer.Required {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func == (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where { public static func == (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
return Where(attribute.keyPath, isEqualTo: value) return Where(attribute.keyPath, isEqualTo: value)
} }
@@ -181,7 +218,7 @@ public extension ValueContainer.Required {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func != (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where { public static func != (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
return !Where(attribute.keyPath, isEqualTo: value) return !Where(attribute.keyPath, isEqualTo: value)
} }
@@ -193,7 +230,7 @@ public extension ValueContainer.Required {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func < (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where { public static func < (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
return Where("%K < %@", attribute.keyPath, value) return Where("%K < %@", attribute.keyPath, value)
} }
@@ -205,7 +242,7 @@ public extension ValueContainer.Required {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func > (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where { public static func > (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
return Where("%K > %@", attribute.keyPath, value) return Where("%K > %@", attribute.keyPath, value)
} }
@@ -217,7 +254,7 @@ public extension ValueContainer.Required {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func <= (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where { public static func <= (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
return Where("%K <= %@", attribute.keyPath, value) return Where("%K <= %@", attribute.keyPath, value)
} }
@@ -229,7 +266,7 @@ public extension ValueContainer.Required {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func >= (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where { public static func >= (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
return Where("%K >= %@", attribute.keyPath, value) return Where("%K >= %@", attribute.keyPath, value)
} }
@@ -241,7 +278,7 @@ public extension ValueContainer.Required {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func ~= <S: Sequence>(_ sequence: S, _ attribute: ValueContainer<O>.Required<V>) -> Where where S.Iterator.Element == V { public static func ~= <S: Sequence>(_ sequence: S, _ attribute: ValueContainer<O>.Required<V>) -> Where<O> where S.Iterator.Element == V {
return Where(attribute.keyPath, isMemberOf: sequence) return Where(attribute.keyPath, isMemberOf: sequence)
} }
@@ -259,7 +296,7 @@ public extension ValueContainer.Optional {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func == (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where { public static func == (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
return Where(attribute.keyPath, isEqualTo: value) return Where(attribute.keyPath, isEqualTo: value)
} }
@@ -271,7 +308,7 @@ public extension ValueContainer.Optional {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func != (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where { public static func != (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
return !Where(attribute.keyPath, isEqualTo: value) return !Where(attribute.keyPath, isEqualTo: value)
} }
@@ -283,7 +320,7 @@ public extension ValueContainer.Optional {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func < (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where { public static func < (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
if let value = value { if let value = value {
@@ -302,7 +339,7 @@ public extension ValueContainer.Optional {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func > (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where { public static func > (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
if let value = value { if let value = value {
@@ -321,7 +358,7 @@ public extension ValueContainer.Optional {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func <= (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where { public static func <= (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
if let value = value { if let value = value {
@@ -340,7 +377,7 @@ public extension ValueContainer.Optional {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func >= (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where { public static func >= (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
if let value = value { if let value = value {
@@ -359,7 +396,7 @@ public extension ValueContainer.Optional {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func ~= <S: Sequence>(_ sequence: S, _ attribute: ValueContainer<O>.Optional<V>) -> Where where S.Iterator.Element == V { public static func ~= <S: Sequence>(_ sequence: S, _ attribute: ValueContainer<O>.Optional<V>) -> Where<O> where S.Iterator.Element == V {
return Where(attribute.keyPath, isMemberOf: sequence) return Where(attribute.keyPath, isMemberOf: sequence)
} }
@@ -377,7 +414,7 @@ public extension RelationshipContainer.ToOne {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func == (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where { public static func == (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where<O> {
return Where(relationship.keyPath, isEqualTo: object) return Where(relationship.keyPath, isEqualTo: object)
} }
@@ -389,7 +426,7 @@ public extension RelationshipContainer.ToOne {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func != (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where { public static func != (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where<O> {
return !Where(relationship.keyPath, isEqualTo: object) return !Where(relationship.keyPath, isEqualTo: object)
} }
@@ -401,7 +438,7 @@ public extension RelationshipContainer.ToOne {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func ~= (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where { public static func ~= (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where<O> {
return Where(relationship.keyPath, isEqualTo: object) return Where(relationship.keyPath, isEqualTo: object)
} }
@@ -413,7 +450,7 @@ public extension RelationshipContainer.ToOne {
``` ```
*/ */
@inline(__always) @inline(__always)
public static func ~= <S: Sequence>(_ sequence: S, _ relationship: RelationshipContainer<O>.ToOne<D>) -> Where where S.Iterator.Element == D { public static func ~= <S: Sequence>(_ sequence: S, _ relationship: RelationshipContainer<O>.ToOne<D>) -> Where<O> where S.Iterator.Element == D {
return Where(relationship.keyPath, isMemberOf: sequence) return Where(relationship.keyPath, isMemberOf: sequence)
} }

View File

@@ -38,7 +38,7 @@ public extension DataStack {
- parameter object: the `DynamicObject` to observe changes from - parameter object: the `DynamicObject` to observe changes from
- returns: a `ObjectMonitor` that monitors changes to `object` - returns: a `ObjectMonitor` that monitors changes to `object`
*/ */
public func monitorObject<T>(_ object: T) -> ObjectMonitor<T> { public func monitorObject<D>(_ object: D) -> ObjectMonitor<D> {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public func monitorList<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> { public func monitorList<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> ListMonitor<D> {
return self.monitorList(from, fetchClauses) 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public func monitorList<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> { public func monitorList<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -82,7 +82,7 @@ public extension DataStack {
CoreStore.assert( CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false, fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(ListMonitor<T>.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<D>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy<D>.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 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) { public func monitorList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ fetchClauses: FetchClause...) {
self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
} }
@@ -107,7 +107,7 @@ public extension DataStack {
- parameter from: a `From` clause indicating the entity type - 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) { public func monitorList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ fetchClauses: [FetchClause]) {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -123,7 +123,7 @@ public extension DataStack {
CoreStore.assert( CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false, fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(ListMonitor<T>.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<D>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy<D>.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor."
) )
}, },
createAsynchronously: createAsynchronously 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> { public func monitorSectionedList<D>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<D> {
return self.monitorSectionedList(from, sectionBy, fetchClauses) 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> { public func monitorSectionedList<D>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -168,7 +168,7 @@ public extension DataStack {
CoreStore.assert( CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false, fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(ListMonitor<T>.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<D>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy<D>.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 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { public func monitorSectionedList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) 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 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { public func monitorSectionedList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -212,7 +212,7 @@ public extension DataStack {
CoreStore.assert( CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false, fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(ListMonitor<T>.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<D>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy<D>.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor."
) )
}, },
createAsynchronously: createAsynchronously createAsynchronously: createAsynchronously

View File

@@ -39,7 +39,7 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter object: a reference to the object created/fetched outside the `DataStack` - 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. - returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/ */
public func fetchExisting<T: DynamicObject>(_ object: T) -> T? { public func fetchExisting<D: DynamicObject>(_ object: D) -> D? {
return self.mainContext.fetchExisting(object) return self.mainContext.fetchExisting(object)
} }
@@ -50,7 +50,7 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter objectID: the `NSManagedObjectID` for the object - parameter objectID: the `NSManagedObjectID` for the object
- returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found. - returns: the `DynamicObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/ */
public func fetchExisting<T: DynamicObject>(_ objectID: NSManagedObjectID) -> T? { public func fetchExisting<D: DynamicObject>(_ objectID: NSManagedObjectID) -> D? {
return self.mainContext.fetchExisting(objectID) 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` - parameter objects: an array of `DynamicObject`s created/fetched outside the `DataStack`
- returns: the `DynamicObject` array for objects that exists in the `DataStack` - returns: the `DynamicObject` array for objects that exists in the `DataStack`
*/ */
public func fetchExisting<T: DynamicObject, S: Sequence>(_ objects: S) -> [T] where S.Iterator.Element == T { public func fetchExisting<D: DynamicObject, S: Sequence>(_ objects: S) -> [D] where S.Iterator.Element == D {
return self.mainContext.fetchExisting(objects) return self.mainContext.fetchExisting(objects)
} }
@@ -72,7 +72,7 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter objectIDs: the `NSManagedObjectID` array for the objects - parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `DynamicObject` array for objects that exists in the `DataStack` - returns: the `DynamicObject` array for objects that exists in the `DataStack`
*/ */
public func fetchExisting<T: DynamicObject, S: Sequence>(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { public func fetchExisting<D: DynamicObject, S: Sequence>(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID {
return self.mainContext.fetchExisting(objectIDs) 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. - 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 - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
*/ */
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? { public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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 - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
*/ */
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? { public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -109,6 +109,16 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchOne(from, fetchClauses) return self.mainContext.fetchOne(from, fetchClauses)
} }
// TODO: docs
public func fetchOne<B: FetchChainableBuilderType>(_ 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. 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. - 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 - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
*/ */
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? { public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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 - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
*/ */
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? { public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -141,6 +151,16 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchAll(from, fetchClauses) return self.mainContext.fetchAll(from, fetchClauses)
} }
// TODO: docs
public func fetchAll<B: FetchChainableBuilderType>(_ 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. 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. - 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 - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? { public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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 - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? { public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -173,6 +193,16 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchCount(from, fetchClauses) return self.mainContext.fetchCount(from, fetchClauses)
} }
// TODO: docs
public func fetchCount<B: FetchChainableBuilderType>(_ 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. 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. - 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 - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
*/ */
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { public func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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 - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
*/ */
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { public func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -205,6 +235,16 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchObjectID(from, fetchClauses) return self.mainContext.fetchObjectID(from, fetchClauses)
} }
// TODO: docs
public func fetchObjectID<B: FetchChainableBuilderType>(_ 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. 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. - 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 - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { public func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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 - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { public func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -237,6 +277,16 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchObjectIDs(from, fetchClauses) return self.mainContext.fetchObjectIDs(from, fetchClauses)
} }
// TODO: docs
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ 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 // 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,

View File

@@ -79,9 +79,9 @@ extension NSManagedObject: DynamicObject {
public class func cs_fromRaw(object: NSManagedObject) -> Self { public class func cs_fromRaw(object: NSManagedObject) -> Self {
@inline(__always) @inline(__always)
func forceCast<T: NSManagedObject>(_ value: Any) -> T { func forceCast<D: NSManagedObject>(_ value: Any) -> D {
return value as! T return value as! D
} }
return forceCast(object) return forceCast(object)
} }
@@ -125,9 +125,9 @@ extension CoreStoreObject {
if let coreStoreObject = object.coreStoreObject { if let coreStoreObject = object.coreStoreObject {
@inline(__always) @inline(__always)
func forceCast<T: CoreStoreObject>(_ value: CoreStoreObject) -> T { func forceCast<D: CoreStoreObject>(_ value: CoreStoreObject) -> D {
return value as! T return value as! D
} }
return forceCast(coreStoreObject) return forceCast(coreStoreObject)
} }

View File

@@ -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<T: DynamicObject> {
public let from: From<T>
public let fetchClauses: [FetchClause] = []
internal init(from: From<T>) {
self.from = from
}
}
extension From: ClauseChain {
public typealias ObjectType = T
public typealias TraitType = FetchTrait
public var builder: ChainedClauseBuilder<T> {
return .init(from: self)
}
}
public struct ChainedWhere<D: DynamicObject, T: ClauseTrait>: ClauseChain {
public typealias ObjectType = D
public typealias TraitType = T
public let builder: ChainedClauseBuilder<ObjectType>
fileprivate init(builder: ChainedClauseBuilder<ObjectType>) {
var newBuilder = builder
// newBuilder.fetchClauses.append(Where())
self.builder = newBuilder
}
}
public struct ChainedOrderBy<D: DynamicObject, T: ClauseTrait>: ClauseChain {
public typealias ObjectType = D
public typealias TraitType = T
public let builder: ChainedClauseBuilder<ObjectType>
fileprivate init(builder: ChainedClauseBuilder<ObjectType>) {
var newBuilder = builder
// newBuilder.fetchClauses.append(Where())
self.builder = newBuilder
}
}
public struct ChainedSelect<D: DynamicObject, T: ClauseTrait>: ClauseChain {
public typealias ObjectType = D
public typealias TraitType = T
public let builder: ChainedClauseBuilder<ObjectType>
fileprivate init(builder: ChainedClauseBuilder<ObjectType>) {
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<ObjectType> { get }
}
public extension ClauseChain where Self.TraitType == FetchTrait {
public func `where`() -> ChainedWhere<ObjectType, FetchTrait> {
return .init(builder: self.builder)
}
public func orderBy() -> ChainedOrderBy<ObjectType, FetchTrait> {
return .init(builder: self.builder)
}
public func select() -> ChainedSelect<ObjectType, QueryTrait> {
return .init(builder: self.builder)
}
}
public extension ClauseChain where Self.TraitType == QueryTrait {
public func `where`() -> ChainedWhere<ObjectType, QueryTrait> {
return .init(builder: self.builder)
}
public func orderBy() -> ChainedOrderBy<ObjectType, QueryTrait> {
return .init(builder: self.builder)
}
}

View File

@@ -40,7 +40,7 @@ public protocol FetchableSource: class {
- parameter object: a reference to the object created/fetched outside the `FetchableSource`'s context - 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. - returns: the `DynamicObject` instance if the object exists in the `FetchableSource`'s context, or `nil` if not found.
*/ */
func fetchExisting<T: DynamicObject>(_ object: T) -> T? func fetchExisting<D: DynamicObject>(_ object: D) -> D?
/** /**
Fetches the `DynamicObject` instance in the `FetchableSource`'s context from an `NSManagedObjectID`. 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 - parameter objectID: the `NSManagedObjectID` for the object
- returns: the `DynamicObject` instance if the object exists in the `FetchableSource`, or `nil` if not found. - returns: the `DynamicObject` instance if the object exists in the `FetchableSource`, or `nil` if not found.
*/ */
func fetchExisting<T: DynamicObject>(_ objectID: NSManagedObjectID) -> T? func fetchExisting<D: DynamicObject>(_ objectID: NSManagedObjectID) -> D?
/** /**
Fetches the `DynamicObject` instances in the `FetchableSource`'s context from references created from another managed object context. 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 - 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` - returns: the `DynamicObject` array for objects that exists in the `FetchableSource`
*/ */
func fetchExisting<T: DynamicObject, S: Sequence>(_ objects: S) -> [T] where S.Iterator.Element == T func fetchExisting<D: DynamicObject, S: Sequence>(_ objects: S) -> [D] where S.Iterator.Element == D
/** /**
Fetches the `DynamicObject` instances in the `FetchableSource`'s context from a list of `NSManagedObjectID`. 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 - parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `DynamicObject` array for objects that exists in the `FetchableSource`'s context - returns: the `DynamicObject` array for objects that exists in the `FetchableSource`'s context
*/ */
func fetchExisting<T: DynamicObject, S: Sequence>(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID func fetchExisting<D: DynamicObject, S: Sequence>(_ 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. 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. - 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 - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
*/ */
func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D?
/** /**
Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s
*/ */
func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D?
// TODO: docs
func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType?
/** /**
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
*/ */
func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]?
/** /**
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s
*/ */
func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]?
// TODO: docs
func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]?
/** /**
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int?
/** /**
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int?
// TODO: docs
func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int?
/** /**
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
*/ */
func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> NSManagedObjectID?
/** /**
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s
*/ */
func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID?
// TODO: docs
func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) -> NSManagedObjectID?
/** /**
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]?
/** /**
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. 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. - 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 - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s
*/ */
func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]?
// TODO: docs
func fetchObjectIDs<B: FetchChainableBuilderType>(_ 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. 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.

View File

@@ -39,12 +39,12 @@ import CoreData
let person = transaction.fetchOne(From<Person>("Configuration1")) let person = transaction.fetchOne(From<Person>("Configuration1"))
``` ```
*/ */
public struct From<T: DynamicObject> { public struct From<D: DynamicObject> {
/** /**
The associated `NSManagedObject` or `CoreStoreObject` entity class 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. The `NSPersistentStore` configuration names to associate objects from.
@@ -60,7 +60,7 @@ public struct From<T: DynamicObject> {
*/ */
public init() { public init() {
self.init(entityClass: T.self, configurations: nil) self.init(entityClass: D.self, configurations: nil)
} }
/** /**
@@ -70,7 +70,7 @@ public struct From<T: DynamicObject> {
``` ```
- parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type - parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type
*/ */
public init(_ entity: T.Type) { public init(_ entity: D.Type) {
self.init(entityClass: entity, configurations: nil) self.init(entityClass: entity, configurations: nil)
} }
@@ -85,7 +85,7 @@ public struct From<T: DynamicObject> {
*/ */
public init(_ configuration: ModelConfiguration, _ otherConfigurations: ModelConfiguration...) { 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<T: DynamicObject> {
*/ */
public init(_ configurations: [ModelConfiguration]) { 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<T: DynamicObject> {
- 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 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) - 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) self.init(entityClass: entity, configurations: [configuration] + otherConfigurations)
} }
@@ -122,7 +122,7 @@ public struct From<T: DynamicObject> {
- parameter entity: the associated `NSManagedObject` or `CoreStoreObject` type - 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. - 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) self.init(entityClass: entity, configurations: configurations)
} }
@@ -132,7 +132,7 @@ public struct From<T: DynamicObject> {
internal let findPersistentStores: (_ context: NSManagedObjectContext) -> [NSPersistentStore]? 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.entityClass = entityClass
self.configurations = configurations self.configurations = configurations
@@ -167,7 +167,7 @@ public struct From<T: DynamicObject> {
// MARK: Private // MARK: Private
private init(entityClass: T.Type, configurations: [ModelConfiguration]?) { private init(entityClass: D.Type, configurations: [ModelConfiguration]?) {
self.entityClass = entityClass self.entityClass = entityClass
self.configurations = configurations self.configurations = configurations

View File

@@ -39,12 +39,12 @@ import CoreData
let person = transaction.create(Into<MyPersonEntity>("Configuration1")) let person = transaction.create(Into<MyPersonEntity>("Configuration1"))
``` ```
*/ */
public struct Into<T: DynamicObject>: Hashable { public struct Into<D: DynamicObject>: Hashable {
/** /**
The associated `NSManagedObject` or `CoreStoreObject` entity class 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. The `NSPersistentStore` configuration name to associate objects from.
@@ -60,7 +60,7 @@ public struct Into<T: DynamicObject>: Hashable {
*/ */
public init() { 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<T: DynamicObject>: Hashable {
``` ```
- parameter entity: the `NSManagedObject` type to be created - 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) self.init(entityClass: entity, configuration: nil, inferStoreIfPossible: true)
} }
@@ -84,7 +84,7 @@ public struct Into<T: DynamicObject>: Hashable {
*/ */
public init(_ configuration: ModelConfiguration) { 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<T: DynamicObject>: Hashable {
- parameter entity: the `NSManagedObject` type to be created - 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. - 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) self.init(entityClass: entity, configuration: configuration, inferStoreIfPossible: false)
} }
@@ -125,7 +125,7 @@ public struct Into<T: DynamicObject>: Hashable {
internal let inferStoreIfPossible: Bool 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.entityClass = entityClass
self.configuration = configuration self.configuration = configuration

View File

@@ -42,7 +42,7 @@ public extension DataStack {
- returns: an `NSFetchedResultsController` that observes the `DataStack` - returns: an `NSFetchedResultsController` that observes the `DataStack`
*/ */
@nonobjc @nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<T> { public func createFetchedResultsController<D: NSManagedObject>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<D> {
return createFRC( return createFRC(
fromContext: self.mainContext, fromContext: self.mainContext,
@@ -62,7 +62,7 @@ public extension DataStack {
- returns: an `NSFetchedResultsController` that observes the `DataStack` - returns: an `NSFetchedResultsController` that observes the `DataStack`
*/ */
@nonobjc @nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> { public func createFetchedResultsController<D: NSManagedObject>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<D> {
return createFRC( return createFRC(
fromContext: self.mainContext, fromContext: self.mainContext,
@@ -81,7 +81,7 @@ public extension DataStack {
- returns: an `NSFetchedResultsController` that observes the `DataStack` - returns: an `NSFetchedResultsController` that observes the `DataStack`
*/ */
@nonobjc @nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<T> { public func createFetchedResultsController<D: NSManagedObject>(_ from: From<D>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<D> {
return createFRC( return createFRC(
fromContext: self.mainContext, fromContext: self.mainContext,
@@ -100,7 +100,7 @@ public extension DataStack {
- returns: an `NSFetchedResultsController` that observes the `DataStack` - returns: an `NSFetchedResultsController` that observes the `DataStack`
*/ */
@nonobjc @nonobjc
public func createFetchedResultsController<T: NSManagedObject>(forDataStack dataStack: DataStack, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> { public func createFetchedResultsController<D: NSManagedObject>(forDataStack dataStack: DataStack, _ from: From<D>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<D> {
return createFRC( return createFRC(
fromContext: self.mainContext, fromContext: self.mainContext,
@@ -127,7 +127,7 @@ public extension UnsafeDataTransaction {
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction` - returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
*/ */
@nonobjc @nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<T> { public func createFetchedResultsController<D: NSManagedObject>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<D> {
return createFRC( return createFRC(
fromContext: self.context, fromContext: self.context,
@@ -147,7 +147,7 @@ public extension UnsafeDataTransaction {
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction` - returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
*/ */
@nonobjc @nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> { public func createFetchedResultsController<D: NSManagedObject>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<D> {
return createFRC( return createFRC(
fromContext: self.context, fromContext: self.context,
@@ -166,7 +166,7 @@ public extension UnsafeDataTransaction {
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction` - returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
*/ */
@nonobjc @nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<T> { public func createFetchedResultsController<D: NSManagedObject>(_ from: From<D>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<D> {
return createFRC( return createFRC(
fromContext: self.context, fromContext: self.context,
@@ -185,7 +185,7 @@ public extension UnsafeDataTransaction {
- returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction` - returns: an `NSFetchedResultsController` that observes the `UnsafeDataTransaction`
*/ */
@nonobjc @nonobjc
public func createFetchedResultsController<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> { public func createFetchedResultsController<D: NSManagedObject>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController<D> {
return createFRC( return createFRC(
fromContext: self.context, fromContext: self.context,
@@ -201,7 +201,7 @@ public extension UnsafeDataTransaction {
// MARK: - Private // MARK: - Private
@available(OSX 10.12, *) @available(OSX 10.12, *)
fileprivate func createFRC<T: NSManagedObject>(fromContext context: NSManagedObjectContext, from: From<T>, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController<T> { fileprivate func createFRC<D: NSManagedObject>(fromContext context: NSManagedObjectContext, from: From<D>, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController<D> {
let controller = CoreStoreFetchedResultsController( let controller = CoreStoreFetchedResultsController(
context: context, context: context,
@@ -214,7 +214,7 @@ fileprivate func createFRC<T: NSManagedObject>(fromContext context: NSManagedObj
CoreStore.assert( CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false, fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController<NSManagedObject>.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<D>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy<D>.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor."
) )
} }
) )

View File

@@ -34,7 +34,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
// MARK: FetchableSource // MARK: FetchableSource
@nonobjc @nonobjc
public func fetchExisting<T: DynamicObject>(_ object: T) -> T? { public func fetchExisting<D: DynamicObject>(_ object: D) -> D? {
let rawObject = object.cs_toRaw() let rawObject = object.cs_toRaw()
if rawObject.objectID.isTemporaryID { if rawObject.objectID.isTemporaryID {
@@ -62,7 +62,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return object return object
} }
return T.cs_fromRaw(object: existingRawObject) return D.cs_fromRaw(object: existingRawObject)
} }
catch { catch {
@@ -75,12 +75,12 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
} }
@nonobjc @nonobjc
public func fetchExisting<T: DynamicObject>(_ objectID: NSManagedObjectID) -> T? { public func fetchExisting<D: DynamicObject>(_ objectID: NSManagedObjectID) -> D? {
do { do {
let existingObject = try self.existingObject(with: objectID) let existingObject = try self.existingObject(with: objectID)
return T.cs_fromRaw(object: existingObject) return D.cs_fromRaw(object: existingObject)
} }
catch _ { catch _ {
@@ -89,25 +89,25 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
} }
@nonobjc @nonobjc
public func fetchExisting<T: DynamicObject, S: Sequence>(_ objects: S) -> [T] where S.Iterator.Element == T { public func fetchExisting<D: DynamicObject, S: Sequence>(_ objects: S) -> [D] where S.Iterator.Element == D {
return objects.flatMap({ self.fetchExisting($0.cs_id()) }) return objects.flatMap({ self.fetchExisting($0.cs_id()) })
} }
@nonobjc @nonobjc
public func fetchExisting<T: DynamicObject, S: Sequence>(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { public func fetchExisting<D: DynamicObject, S: Sequence>(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID {
return objectIDs.flatMap({ self.fetchExisting($0) }) return objectIDs.flatMap({ self.fetchExisting($0) })
} }
@nonobjc @nonobjc
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? { public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D? {
return self.fetchOne(from, fetchClauses) return self.fetchOne(from, fetchClauses)
} }
@nonobjc @nonobjc
public func fetchOne<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? { public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) 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) return self.fetchOne(fetchRequest.dynamicCast()).flatMap(from.entityClass.cs_fromRaw)
} }
// TODO: docs
@nonobjc @nonobjc
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? { public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
return self.fetchOne(clauseChain.from, clauseChain.fetchClauses)
}
@nonobjc
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]? {
return self.fetchAll(from, fetchClauses) return self.fetchAll(from, fetchClauses)
} }
@nonobjc @nonobjc
public func fetchAll<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? { public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
@@ -147,14 +154,21 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw) return self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw)
} }
// TODO: docs
@nonobjc @nonobjc
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? { public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
return self.fetchAll(clauseChain.from, clauseChain.fetchClauses)
}
@nonobjc
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int? {
return self.fetchCount(from, fetchClauses) return self.fetchCount(from, fetchClauses)
} }
@nonobjc @nonobjc
public func fetchCount<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? { public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
@@ -167,14 +181,21 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return self.fetchCount(fetchRequest.dynamicCast()) return self.fetchCount(fetchRequest.dynamicCast())
} }
// TODO: docs
@nonobjc @nonobjc
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
return self.fetchCount(clauseChain.from, clauseChain.fetchClauses)
}
@nonobjc
public func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
return self.fetchObjectID(from, fetchClauses) return self.fetchObjectID(from, fetchClauses)
} }
@nonobjc @nonobjc
public func fetchObjectID<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { public func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
@@ -190,14 +211,21 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return self.fetchObjectID(fetchRequest.dynamicCast()) return self.fetchObjectID(fetchRequest.dynamicCast())
} }
// TODO: docs
@nonobjc @nonobjc
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) -> NSManagedObjectID? {
return self.fetchObjectID(clauseChain.from, clauseChain.fetchClauses)
}
@nonobjc
public func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
return self.fetchObjectIDs(from, fetchClauses) return self.fetchObjectIDs(from, fetchClauses)
} }
@nonobjc @nonobjc
public func fetchObjectIDs<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { public func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
@@ -213,6 +241,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return self.fetchObjectIDs(fetchRequest.dynamicCast()) return self.fetchObjectIDs(fetchRequest.dynamicCast())
} }
// TODO: docs
@nonobjc
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) -> [NSManagedObjectID]? {
return self.fetchObjectIDs(clauseChain.from, clauseChain.fetchClauses)
}
@nonobjc @nonobjc
internal func fetchObjectIDs(_ fetchRequest: NSFetchRequest<NSManagedObjectID>) -> [NSManagedObjectID]? { internal func fetchObjectIDs(_ fetchRequest: NSFetchRequest<NSManagedObjectID>) -> [NSManagedObjectID]? {
@@ -244,13 +279,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
// MARK: QueryableSource // MARK: QueryableSource
@nonobjc @nonobjc
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
return self.queryValue(from, selectClause, queryClauses) return self.queryValue(from, selectClause, queryClauses)
} }
@nonobjc @nonobjc
public func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
@@ -269,13 +304,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
} }
@nonobjc @nonobjc
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
return self.queryAttributes(from, selectClause, queryClauses) return self.queryAttributes(from, selectClause, queryClauses)
} }
@nonobjc @nonobjc
public func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
@@ -305,13 +340,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
// MARK: Deleting // MARK: Deleting
@nonobjc @nonobjc
internal func deleteAll<T>(_ from: From<T>, _ deleteClauses: DeleteClause...) -> Int? { internal func deleteAll<D>(_ from: From<D>, _ deleteClauses: [FetchClause]) -> Int? {
return self.deleteAll(from, deleteClauses)
}
@nonobjc
internal func deleteAll<T>(_ from: From<T>, _ deleteClauses: [DeleteClause]) -> Int? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
@@ -347,9 +376,9 @@ internal extension NSManagedObjectContext {
// MARK: Fetching // MARK: Fetching
@nonobjc @nonobjc
internal func fetchOne<T: NSManagedObject>(_ fetchRequest: NSFetchRequest<T>) -> T? { internal func fetchOne<D: NSManagedObject>(_ fetchRequest: NSFetchRequest<D>) -> D? {
var fetchResults: [T]? var fetchResults: [D]?
var fetchError: Error? var fetchError: Error?
self.performAndWait { self.performAndWait {
@@ -374,9 +403,9 @@ internal extension NSManagedObjectContext {
} }
@nonobjc @nonobjc
internal func fetchAll<T: NSManagedObject>(_ fetchRequest: NSFetchRequest<T>) -> [T]? { internal func fetchAll<D: NSManagedObject>(_ fetchRequest: NSFetchRequest<D>) -> [D]? {
var fetchResults: [T]? var fetchResults: [D]?
var fetchError: Error? var fetchError: Error?
self.performAndWait { self.performAndWait {
@@ -555,7 +584,7 @@ internal extension NSManagedObjectContext {
// MARK: Deleting // MARK: Deleting
@nonobjc @nonobjc
internal func deleteAll<T: NSManagedObject>(_ fetchRequest: NSFetchRequest<T>) -> Int? { internal func deleteAll<D: NSManagedObject>(_ fetchRequest: NSFetchRequest<D>) -> Int? {
var numberOfDeletedObjects: Int? var numberOfDeletedObjects: Int?
var fetchError: Error? var fetchError: Error?

View File

@@ -273,7 +273,7 @@ public final class ObjectMonitor<D: DynamicObject>: Equatable {
context: context, context: context,
fetchRequest: fetchRequest.dynamicCast(), fetchRequest: fetchRequest.dynamicCast(),
from: From<ObjectType>([objectID.persistentStore?.configurationName]), from: From<ObjectType>([objectID.persistentStore?.configurationName]),
applyFetchClauses: Where("SELF", isEqualTo: objectID).applyToFetchRequest applyFetchClauses: Where<ObjectType>("SELF", isEqualTo: objectID).applyToFetchRequest
) )
let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate() let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate()

View File

@@ -32,31 +32,12 @@ import CoreData
public typealias KeyPathString = String 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 // MARK: - OrderBy
/** /**
The `OrderBy` clause specifies the sort order for results for a fetch or a query. 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<D: DynamicObject>: OrderByClause, FetchClause, QueryClause, DeleteClause, Hashable {
/** /**
Combines two `OrderBy` sort descriptors together Combines two `OrderBy` sort descriptors together
@@ -74,11 +55,6 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
left = left + right left = left + right
} }
/**
The list of sort descriptors
*/
public let sortDescriptors: [NSSortDescriptor]
/** /**
Initializes a `OrderBy` clause with an empty list of sort descriptors 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 - parameter sortKey: a series of `SortKey`s
*/ */
public init(_ sortKey: [SortKey]) { public init(_ sortKeys: [SortKey]) {
self.init( self.init(sortKeys.map({ $0.descriptor }))
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)
}
}
)
} }
/** /**
@@ -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 // MARK: FetchClause, QueryClause, DeleteClause
public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) { public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) {
@@ -171,17 +142,154 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
return (self.sortDescriptors as NSArray).hashValue 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<T>(_ keyPath: KeyPath<D, T>) -> SortKey where D: NSManagedObject {
return .ascending(keyPath._kvcKeyPathString!)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<T>(_ keyPath: KeyPath<D, T>) -> 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<A, T>(_ attribute: KeyPath<D, A>) -> SortKey where A: ValueContainer<D>.Required<T> {
return .ascending(D.meta[keyPath: attribute].keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in ascending order
*/
public static func ascending<A, T>(_ attribute: KeyPath<D, A>) -> SortKey where A: ValueContainer<D>.Optional<T> {
return .ascending(D.meta[keyPath: attribute].keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in ascending order
*/
public static func ascending<A, T>(_ attribute: KeyPath<D, A>) -> SortKey where A: TransformableContainer<D>.Required<T> {
return .ascending(D.meta[keyPath: attribute].keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in ascending order
*/
public static func ascending<A, T>(_ attribute: KeyPath<D, A>) -> SortKey where A: TransformableContainer<D>.Optional<T> {
return .ascending(D.meta[keyPath: attribute].keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<A, T>(_ attribute: KeyPath<D, A>) -> SortKey where A: ValueContainer<D>.Required<T> {
return .descending(D.meta[keyPath: attribute].keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<A, T>(_ attribute: KeyPath<D, A>) -> SortKey where A: ValueContainer<D>.Optional<T> {
return .descending(D.meta[keyPath: attribute].keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<A, T>(_ attribute: KeyPath<D, A>) -> SortKey where A: TransformableContainer<D>.Required<T> {
return .descending(D.meta[keyPath: attribute].keyPath)
}
/**
Indicates that the `KeyPathString` should be sorted in descending order
*/
public static func descending<A, T>(_ attribute: KeyPath<D, A>) -> SortKey where A: TransformableContainer<D>.Optional<T> {
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 Combines multiple `OrderBy` predicates together
*/ */
public func combined() -> OrderBy { public func combined() -> OrderBy<Iterator.Element.ObjectType> {
return OrderBy(self.flatMap({ $0.sortDescriptors })) return OrderBy(self.flatMap({ $0.sortDescriptors }))
} }

View File

@@ -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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ 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. 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
func queryValue<T, U: QueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ 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. 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ 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. 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. - 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<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
func queryAttributes<T>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ 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. 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.

View File

@@ -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 - 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. - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
*/ */
public override func create<T>(_ into: Into<T>) -> T { public override func create<D>(_ into: Into<D>) -> D {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,
@@ -71,7 +71,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited - parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/ */
public override func edit<T: DynamicObject>(_ object: T?) -> T? { public override func edit<D: DynamicObject>(_ object: D?) -> D? {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,
@@ -88,7 +88,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
- parameter objectID: the `NSManagedObjectID` for the object to be edited - parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/ */
public override func edit<T>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? { public override func edit<D>(_ into: Into<D>, _ objectID: NSManagedObjectID) -> D? {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,
@@ -103,7 +103,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
- parameter object: the `NSManagedObject` or `CoreStoreObject` type to be deleted - parameter object: the `NSManagedObject` or `CoreStoreObject` type to be deleted
*/ */
public override func delete<T: DynamicObject>(_ object: T?) { public override func delete<D: DynamicObject>(_ object: D?) {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,
@@ -120,7 +120,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
- parameter object2: another `DynamicObject` to be deleted - parameter object2: another `DynamicObject` to be deleted
- parameter objects: other `DynamicObject`s to be deleted - parameter objects: other `DynamicObject`s to be deleted
*/ */
public override func delete<T: DynamicObject>(_ object1: T?, _ object2: T?, _ objects: T?...) { public override func delete<D: DynamicObject>(_ object1: D?, _ object2: D?, _ objects: D?...) {
CoreStore.assert( CoreStore.assert(
!self.isCommitted, !self.isCommitted,

View File

@@ -38,7 +38,7 @@ public extension UnsafeDataTransaction {
- parameter object: the `DynamicObject` to observe changes from - parameter object: the `DynamicObject` to observe changes from
- returns: a `ObjectMonitor` that monitors changes to `object` - returns: a `ObjectMonitor` that monitors changes to `object`
*/ */
public func monitorObject<T>(_ object: T) -> ObjectMonitor<T> { public func monitorObject<D>(_ object: D) -> ObjectMonitor<D> {
return ObjectMonitor( return ObjectMonitor(
unsafeTransaction: self, 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public func monitorList<T>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> { public func monitorList<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> ListMonitor<D> {
return self.monitorList(from, fetchClauses) 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public func monitorList<T>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> { public func monitorList<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
CoreStore.assert( CoreStore.assert(
fetchClauses.filter { $0 is OrderBy }.count > 0, fetchClauses.filter { $0 is OrderBy<D> }.count > 0,
"A ListMonitor requires an OrderBy clause." "A ListMonitor requires an OrderBy clause."
) )
@@ -90,7 +90,7 @@ public extension UnsafeDataTransaction {
- parameter from: a `From` clause indicating the entity type - 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: FetchClause...) { public func monitorList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ fetchClauses: FetchClause...) {
self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses)
} }
@@ -102,10 +102,10 @@ public extension UnsafeDataTransaction {
- parameter from: a `From` clause indicating the entity type - 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public func monitorList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ fetchClauses: [FetchClause]) { public func monitorList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ fetchClauses: [FetchClause]) {
CoreStore.assert( CoreStore.assert(
fetchClauses.filter { $0 is OrderBy }.count > 0, fetchClauses.filter { $0 is OrderBy<D> }.count > 0,
"A ListMonitor requires an OrderBy clause." "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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> { public func monitorSectionedList<D>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<D> {
return self.monitorSectionedList(from, sectionBy, fetchClauses) 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. - 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 - returns: a `ListMonitor` instance that monitors changes to the list
*/ */
public func monitorSectionedList<T>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> { public func monitorSectionedList<D>(_ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
CoreStore.assert( CoreStore.assert(
fetchClauses.filter { $0 is OrderBy }.count > 0, fetchClauses.filter { $0 is OrderBy<D> }.count > 0,
"A ListMonitor requires an OrderBy clause." "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 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { public func monitorSectionedList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) {
self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) 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 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. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/ */
public func monitorSectionedList<T>(createAsynchronously: @escaping (ListMonitor<T>) -> Void, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { public func monitorSectionedList<D>(createAsynchronously: @escaping (ListMonitor<D>) -> Void, _ from: From<D>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) {
CoreStore.assert( CoreStore.assert(
fetchClauses.filter { $0 is OrderBy }.count > 0, fetchClauses.filter { $0 is OrderBy<D> }.count > 0,
"A ListMonitor requires an OrderBy clause." "A ListMonitor requires an OrderBy clause."
) )

View File

@@ -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<Root, Value>, _ value: Value) -> Where<Root> {
return Where(keyPath._kvcKeyPathString!, isEqualTo: value)
}
public static func != (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> {
return !Where(keyPath._kvcKeyPathString!, isEqualTo: value)
}
public static func ~= <S: Sequence>(_ sequence: S, _ keyPath: KeyPath<Root, Value>) -> Where<Root> where S.Iterator.Element == Value {
return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence)
}
}
// MARK: - KeyPath where Root: NSManagedObject, Value: Optional<QueryableAttributeType & Equatable>
public extension KeyPath where Root: NSManagedObject {
public static func == <V: QueryableAttributeType & Equatable> (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> where Value == Optional<V> {
return Where(keyPath._kvcKeyPathString!, isEqualTo: value)
}
public static func != <V: QueryableAttributeType & Equatable> (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> where Value == Optional<V> {
return !Where(keyPath._kvcKeyPathString!, isEqualTo: value)
}
public static func ~= <S: Sequence, V: QueryableAttributeType & Equatable>(_ sequence: S, _ keyPath: KeyPath<Root, Value>) -> Where<Root> where Value == Optional<V>, 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<Root, Value>, _ value: Value) -> Where<Root> {
return Where("%K < %@", keyPath._kvcKeyPathString!, value)
}
public static func > (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> {
return Where("%K > %@", keyPath._kvcKeyPathString!, value)
}
public static func <= (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> {
return Where("%K <= %@", keyPath._kvcKeyPathString!, value)
}
public static func >= (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> {
return Where("%K >= %@", keyPath._kvcKeyPathString!, value)
}
}
// MARK: - KeyPath where Root: NSManagedObject, Value: Optional<QueryableAttributeType>
public extension KeyPath where Root: NSManagedObject {
public static func < <V: QueryableAttributeType> (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> where Value == Optional<V> {
if let value = value {
return Where("%K < %@", keyPath._kvcKeyPathString!, value)
}
else {
return Where("%K < nil", keyPath._kvcKeyPathString!)
}
}
public static func > <V: QueryableAttributeType> (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> where Value == Optional<V> {
if let value = value {
return Where("%K > %@", keyPath._kvcKeyPathString!, value)
}
else {
return Where("%K > nil", keyPath._kvcKeyPathString!)
}
}
public static func <= <V: QueryableAttributeType> (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> where Value == Optional<V> {
if let value = value {
return Where("%K <= %@", keyPath._kvcKeyPathString!, value)
}
else {
return Where("%K <= nil", keyPath._kvcKeyPathString!)
}
}
public static func >= <V: QueryableAttributeType> (_ keyPath: KeyPath<Root, Value>, _ value: Value) -> Where<Root> where Value == Optional<V> {
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<Root, Value>, _ object: Value) -> Where<Root> {
return Where(keyPath._kvcKeyPathString!, isEqualTo: object)
}
public static func != (_ keyPath: KeyPath<Root, Value>, _ object: Value) -> Where<Root> {
return !Where(keyPath._kvcKeyPathString!, isEqualTo: object)
}
public static func ~= <S: Sequence>(_ sequence: S, _ keyPath: KeyPath<Root, Value>) -> Where<Root> where S.Iterator.Element == Value {
return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence)
}
public static func == (_ keyPath: KeyPath<Root, Value>, _ objectID: NSManagedObjectID?) -> Where<Root> {
return Where(keyPath._kvcKeyPathString!, isEqualTo: objectID)
}
public static func != (_ keyPath: KeyPath<Root, Value>, _ objectID: NSManagedObjectID?) -> Where<Root> {
return !Where(keyPath._kvcKeyPathString!, isEqualTo: objectID)
}
public static func ~= <S: Sequence>(_ sequence: S, _ keyPath: KeyPath<Root, Value>) -> Where<Root> where S.Iterator.Element == NSManagedObjectID {
return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence)
}
}
// MARK: - KeyPath where Root: NSManagedObject, Value: Optional<NSManagedObject>
public extension KeyPath where Root: NSManagedObject {
public static func == <V: NSManagedObject> (_ keyPath: KeyPath<Root, Value>, _ object: Value) -> Where<Root> where Value == Optional<V> {
return Where(keyPath._kvcKeyPathString!, isEqualTo: object)
}
public static func != <V: NSManagedObject> (_ keyPath: KeyPath<Root, Value>, _ object: Value) -> Where<Root> where Value == Optional<V> {
return !Where(keyPath._kvcKeyPathString!, isEqualTo: object)
}
public static func ~= <S: Sequence, V: NSManagedObject>(_ sequence: S, _ keyPath: KeyPath<Root, Value>) -> Where<Root> where Value == Optional<V>, S.Iterator.Element == V {
return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence)
}
public static func == <V: NSManagedObject> (_ keyPath: KeyPath<Root, Value>, _ objectID: NSManagedObjectID?) -> Where<Root> where Value == Optional<V> {
return Where(keyPath._kvcKeyPathString!, isEqualTo: objectID)
}
public static func != <V: NSManagedObject> (_ keyPath: KeyPath<Root, Value>, _ objectID: NSManagedObjectID?) -> Where<Root> where Value == Optional<V> {
return !Where(keyPath._kvcKeyPathString!, isEqualTo: objectID)
}
public static func ~= <S: Sequence, V: NSManagedObject>(_ sequence: S, _ keyPath: KeyPath<Root, Value>) -> Where<Root> where Value == Optional<V>, S.Iterator.Element == NSManagedObjectID {
return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence)
}
}

View File

@@ -32,7 +32,7 @@ import CoreData
/** /**
The `Where` clause specifies the conditions for a fetch or a query. The `Where` clause specifies the conditions for a fetch or a query.
*/ */
public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { public struct Where<D: DynamicObject>: WhereClause, FetchClause, QueryClause, DeleteClause, Hashable {
/** /**
Combines two `Where` predicates together using `AND` operator 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])) 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` 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 keyPath: the keyPath to compare with
- parameter value: the arguments for the `==` operator - parameter value: the arguments for the `==` operator
*/ */
public init<T: QueryableAttributeType>(_ keyPath: KeyPathString, isEqualTo value: T?) { public init<U: QueryableAttributeType>(_ keyPath: KeyPathString, isEqualTo value: U?) {
switch value { switch value {
@@ -207,12 +202,11 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
- parameter keyPath: the keyPath to compare with - parameter keyPath: the keyPath to compare with
- parameter object: the arguments for the `==` operator - parameter object: the arguments for the `==` operator
*/ */
public init<T: DynamicObject>(_ keyPath: KeyPathString, isEqualTo object: T?) { public init<D: DynamicObject>(_ keyPath: KeyPathString, isEqualTo object: D?) {
switch object { switch object {
case nil, case nil:
is NSNull:
self.init(NSPredicate(format: "\(keyPath) == nil")) self.init(NSPredicate(format: "\(keyPath) == nil"))
case let object?: 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 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)) 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<S: Sequence>(_ 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` 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 // MARK: FetchClause, QueryClause, DeleteClause
public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) { public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) {
@@ -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 Combines multiple `Where` predicates together using `AND` operator
*/ */
public func combinedByAnd() -> Where { public func combinedByAnd() -> Where<Iterator.Element.ObjectType> {
return Where(NSCompoundPredicate(type: .and, subpredicates: self.map({ $0.predicate }))) 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 Combines multiple `Where` predicates together using `OR` operator
*/ */
public func combinedByOr() -> Where { public func combinedByOr() -> Where<Iterator.Element.ObjectType> {
return Where(NSCompoundPredicate(type: .or, subpredicates: self.map({ $0.predicate }))) return Where(NSCompoundPredicate(type: .or, subpredicates: self.map({ $0.predicate })))
} }