diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/JohnEstropia.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/JohnEstropia.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..78e6720 Binary files /dev/null and b/.swiftpm/xcode/package.xcworkspace/xcuserdata/JohnEstropia.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/.swiftpm/xcode/xcuserdata/JohnEstropia.xcuserdatad/xcschemes/xcschememanagement.plist b/.swiftpm/xcode/xcuserdata/JohnEstropia.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..22be8b9 --- /dev/null +++ b/.swiftpm/xcode/xcuserdata/JohnEstropia.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + CoreStore.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index c28d06d..ba01750 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -54,15 +54,14 @@ 82BA18CA1C4BBD5900A0916E /* MigrationResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56965231B356B820075EE4A /* MigrationResult.swift */; }; 82BA18CB1C4BBD6400A0916E /* NSManagedObject+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F271AFF84920064E85B /* NSManagedObject+Convenience.swift */; }; 82BA18CC1C4BBD6400A0916E /* Progress+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6A81B50A4B300714891 /* Progress+Convenience.swift */; }; - 82BA18CE1C4BBD7100A0916E /* FetchedResultsControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */; }; - 82BA18CF1C4BBD7100A0916E /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E834BA1B7691F3001D3D50 /* Functions.swift */; }; - 82BA18D01C4BBD7100A0916E /* MigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AB1B51285300714891 /* MigrationManager.swift */; }; - 82BA18D11C4BBD7100A0916E /* NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */; }; + 82BA18CE1C4BBD7100A0916E /* Internals.FetchedResultsControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A6A541BA15F2A007870FD /* Internals.FetchedResultsControllerDelegate.swift */; }; + 82BA18D01C4BBD7100A0916E /* Internals.MigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AB1B51285300714891 /* Internals.MigrationManager.swift */; }; + 82BA18D11C4BBD7100A0916E /* Internals.NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* Internals.NotificationObserver.swift */; }; 82BA18D31C4BBD7100A0916E /* NSManagedObjectContext+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2C1AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift */; }; 82BA18D41C4BBD7100A0916E /* NSManagedObjectContext+Querying.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */; }; 82BA18D51C4BBD7100A0916E /* NSManagedObjectContext+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */; }; 82BA18D61C4BBD7100A0916E /* NSManagedObjectContext+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F331AFF85470064E85B /* NSManagedObjectContext+Transaction.swift */; }; - 82BA18D81C4BBD7100A0916E /* WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* WeakObject.swift */; }; + 82BA18D81C4BBD7100A0916E /* Internals.WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* Internals.WeakObject.swift */; }; 82BA18DC1C4BBD9C00A0916E /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = B5D372821A39CD6900F583D9 /* Model.xcdatamodeld */; }; 82BA18DD1C4BBE1400A0916E /* NSFetchedResultsController+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */; }; B501FDDD1CA8D05000BE22EF /* CSSectionBy.swift in Sources */ = {isa = PBXBuildFile; fileRef = B501FDDC1CA8D05000BE22EF /* CSSectionBy.swift */; }; @@ -90,10 +89,10 @@ B512608A1E9B252B00402229 /* NSEntityDescription+DynamicModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260881E9B252B00402229 /* NSEntityDescription+DynamicModel.swift */; }; B512608B1E9B252B00402229 /* NSEntityDescription+DynamicModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260881E9B252B00402229 /* NSEntityDescription+DynamicModel.swift */; }; B512608C1E9B252B00402229 /* NSEntityDescription+DynamicModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260881E9B252B00402229 /* NSEntityDescription+DynamicModel.swift */; }; - B51260931E9B28F100402229 /* EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* EntityIdentifier.swift */; }; - B51260941E9B28F100402229 /* EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* EntityIdentifier.swift */; }; - B51260951E9B28F100402229 /* EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* EntityIdentifier.swift */; }; - B51260961E9B28F100402229 /* EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* EntityIdentifier.swift */; }; + B51260931E9B28F100402229 /* Internals.EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* Internals.EntityIdentifier.swift */; }; + B51260941E9B28F100402229 /* Internals.EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* Internals.EntityIdentifier.swift */; }; + B51260951E9B28F100402229 /* Internals.EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* Internals.EntityIdentifier.swift */; }; + B51260961E9B28F100402229 /* Internals.EntityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51260921E9B28F100402229 /* Internals.EntityIdentifier.swift */; }; B51B5C2B22D43931009FA3BA /* String+KeyPaths.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51B5C2A22D43931009FA3BA /* String+KeyPaths.swift */; }; B51B5C2D22D43E38009FA3BA /* KeyPath+KeyPaths.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51B5C2C22D43E38009FA3BA /* KeyPath+KeyPaths.swift */; }; B51FE5AB1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; @@ -128,16 +127,15 @@ B5220E171D1306DF009BC71E /* UnsafeDataTransaction+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E21C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift */; }; B5220E181D130711009BC71E /* ObjectObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F1F1AFF84860064E85B /* ObjectObserver.swift */; }; B5220E191D130761009BC71E /* ListMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F1D1AFF84860064E85B /* ListMonitor.swift */; }; - B5220E1A1D130791009BC71E /* CoreStoreFetchedResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */; }; + B5220E1A1D130791009BC71E /* Internals.CoreStoreFetchedResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E61C6E3A5900B1AF90 /* Internals.CoreStoreFetchedResultsController.swift */; }; B5220E1B1D13079B009BC71E /* CSCoreStore+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1B5A11CAA4365007FD580 /* CSCoreStore+Observing.swift */; }; - B5220E1C1D130801009BC71E /* FetchedResultsControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */; }; + B5220E1C1D130801009BC71E /* Internals.FetchedResultsControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A6A541BA15F2A007870FD /* Internals.FetchedResultsControllerDelegate.swift */; }; B5220E1D1D13080A009BC71E /* CSDataStack+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1B59C1CAA2568007FD580 /* CSDataStack+Observing.swift */; }; B5220E1E1D13080D009BC71E /* CSListMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B501FDE11CA8D1F500BE22EF /* CSListMonitor.swift */; }; B5220E1F1D130810009BC71E /* CSListObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B501FDE61CA8D20500BE22EF /* CSListObserver.swift */; }; B5220E201D130813009BC71E /* CSObjectMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1B5921CAA0C15007FD580 /* CSObjectMonitor.swift */; }; B5220E211D130816009BC71E /* CSObjectObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1B5971CAA0C23007FD580 /* CSObjectObserver.swift */; }; B5220E221D130818009BC71E /* CSSectionBy.swift in Sources */ = {isa = PBXBuildFile; fileRef = B501FDDC1CA8D05000BE22EF /* CSSectionBy.swift */; }; - B5220E231D130826009BC71E /* NSFetchedResultsController+ObjectiveC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53FBA1D1CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift */; }; B5220E241D13085E009BC71E /* NSFetchedResultsController+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */; }; B5220E251D13088E009BC71E /* ListObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F1E1AFF84860064E85B /* ListObserver.swift */; }; B5220E261D1308C2009BC71E /* ListObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5220E0F1D0DA6AB009BC71E /* ListObserverTests.swift */; }; @@ -202,14 +200,13 @@ B52DD1BC1BE1F94000949AFE /* MigrationResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56965231B356B820075EE4A /* MigrationResult.swift */; }; B52DD1BD1BE1F94300949AFE /* NSManagedObject+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F271AFF84920064E85B /* NSManagedObject+Convenience.swift */; }; B52DD1BE1BE1F94300949AFE /* Progress+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6A81B50A4B300714891 /* Progress+Convenience.swift */; }; - B52DD1C11BE1F94600949AFE /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E834BA1B7691F3001D3D50 /* Functions.swift */; }; - B52DD1C21BE1F94600949AFE /* MigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AB1B51285300714891 /* MigrationManager.swift */; }; - B52DD1C31BE1F94600949AFE /* NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */; }; + B52DD1C21BE1F94600949AFE /* Internals.MigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AB1B51285300714891 /* Internals.MigrationManager.swift */; }; + B52DD1C31BE1F94600949AFE /* Internals.NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* Internals.NotificationObserver.swift */; }; B52DD1C61BE1F94600949AFE /* NSManagedObjectContext+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2C1AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift */; }; B52DD1C71BE1F94600949AFE /* NSManagedObjectContext+Querying.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */; }; B52DD1C81BE1F94600949AFE /* NSManagedObjectContext+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */; }; B52DD1C91BE1F94600949AFE /* NSManagedObjectContext+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F331AFF85470064E85B /* NSManagedObjectContext+Transaction.swift */; }; - B52DD1CB1BE1F94600949AFE /* WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* WeakObject.swift */; }; + B52DD1CB1BE1F94600949AFE /* Internals.WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* Internals.WeakObject.swift */; }; B52F742F1E9B50D0005F3DAC /* SchemaHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52F742E1E9B50D0005F3DAC /* SchemaHistory.swift */; }; B52F74301E9B50D0005F3DAC /* SchemaHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52F742E1E9B50D0005F3DAC /* SchemaHistory.swift */; }; B52F74311E9B50D0005F3DAC /* SchemaHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52F742E1E9B50D0005F3DAC /* SchemaHistory.swift */; }; @@ -234,6 +231,7 @@ B52FD3AB1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */; }; B52FD3AC1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */; }; B52FD3AD1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */; }; + B53304AA230BA4F7007C2BD8 /* DynamicObjectMeta.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53304A9230BA4F7007C2BD8 /* DynamicObjectMeta.swift */; }; B533C4DB1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; }; B533C4DC1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; }; B533C4DD1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; }; @@ -270,9 +268,6 @@ B53FBA1A1CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53FBA171CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift */; }; B53FBA1B1CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53FBA171CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift */; }; B53FBA1C1CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53FBA171CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift */; }; - B53FBA1E1CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53FBA1D1CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift */; }; - B53FBA201CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53FBA1D1CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift */; }; - B53FBA211CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53FBA1D1CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift */; }; B546F9581C99B17400D5AC55 /* CSCoreStore+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9571C99B17400D5AC55 /* CSCoreStore+Setup.swift */; }; B546F9591C99B17400D5AC55 /* CSCoreStore+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9571C99B17400D5AC55 /* CSCoreStore+Setup.swift */; }; B546F95A1C99B17400D5AC55 /* CSCoreStore+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9571C99B17400D5AC55 /* CSCoreStore+Setup.swift */; }; @@ -289,10 +284,10 @@ B546F9741C9C553300D5AC55 /* SetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9721C9C553300D5AC55 /* SetupResult.swift */; }; B546F9751C9C553300D5AC55 /* SetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9721C9C553300D5AC55 /* SetupResult.swift */; }; B546F9761C9C553300D5AC55 /* SetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9721C9C553300D5AC55 /* SetupResult.swift */; }; - B5474D152227C08700B21FEC /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5474D142227C08700B21FEC /* CoreStoreFetchRequest.swift */; }; - B5474D162227C08700B21FEC /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5474D142227C08700B21FEC /* CoreStoreFetchRequest.swift */; }; - B5474D172227C08700B21FEC /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5474D142227C08700B21FEC /* CoreStoreFetchRequest.swift */; }; - B5474D182227C08700B21FEC /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5474D142227C08700B21FEC /* CoreStoreFetchRequest.swift */; }; + B5474D152227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5474D142227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift */; }; + B5474D162227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5474D142227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift */; }; + B5474D172227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5474D142227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift */; }; + B5474D182227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5474D142227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift */; }; B5489F3F1CF5EEBC008B4978 /* TestEntity1.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5489F3D1CF5EEBC008B4978 /* TestEntity1.swift */; }; B5489F401CF5EEBC008B4978 /* TestEntity1.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5489F3D1CF5EEBC008B4978 /* TestEntity1.swift */; }; B5489F411CF5EEBC008B4978 /* TestEntity1.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5489F3D1CF5EEBC008B4978 /* TestEntity1.swift */; }; @@ -316,7 +311,7 @@ B549F6741E56A92800FBAB2D /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */; }; B549F6751E56A92800FBAB2D /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */; }; B549F6761E56A92800FBAB2D /* CoreDataNativeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */; }; - B54A6A551BA15F2A007870FD /* FetchedResultsControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */; }; + B54A6A551BA15F2A007870FD /* Internals.FetchedResultsControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A6A541BA15F2A007870FD /* Internals.FetchedResultsControllerDelegate.swift */; }; B5519A401CA1B17B002BEF78 /* ErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A3F1CA1B17B002BEF78 /* ErrorTests.swift */; }; B5519A411CA1B17B002BEF78 /* ErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A3F1CA1B17B002BEF78 /* ErrorTests.swift */; }; B5519A421CA1B17B002BEF78 /* ErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A3F1CA1B17B002BEF78 /* ErrorTests.swift */; }; @@ -394,15 +389,14 @@ B56321A71BD65216006C9394 /* MigrationResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56965231B356B820075EE4A /* MigrationResult.swift */; }; B56321A81BD65219006C9394 /* NSManagedObject+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F271AFF84920064E85B /* NSManagedObject+Convenience.swift */; }; B56321A91BD65219006C9394 /* Progress+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6A81B50A4B300714891 /* Progress+Convenience.swift */; }; - B56321AB1BD6521C006C9394 /* FetchedResultsControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */; }; - B56321AC1BD6521C006C9394 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E834BA1B7691F3001D3D50 /* Functions.swift */; }; - B56321AD1BD6521C006C9394 /* MigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AB1B51285300714891 /* MigrationManager.swift */; }; - B56321AE1BD6521C006C9394 /* NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */; }; + B56321AB1BD6521C006C9394 /* Internals.FetchedResultsControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A6A541BA15F2A007870FD /* Internals.FetchedResultsControllerDelegate.swift */; }; + B56321AD1BD6521C006C9394 /* Internals.MigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AB1B51285300714891 /* Internals.MigrationManager.swift */; }; + B56321AE1BD6521C006C9394 /* Internals.NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* Internals.NotificationObserver.swift */; }; B56321B11BD6521C006C9394 /* NSManagedObjectContext+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2C1AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift */; }; B56321B21BD6521C006C9394 /* NSManagedObjectContext+Querying.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */; }; B56321B31BD6521C006C9394 /* NSManagedObjectContext+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */; }; B56321B41BD6521C006C9394 /* NSManagedObjectContext+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F331AFF85470064E85B /* NSManagedObjectContext+Transaction.swift */; }; - B56321B61BD6521C006C9394 /* WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* WeakObject.swift */; }; + B56321B61BD6521C006C9394 /* Internals.WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* Internals.WeakObject.swift */; }; B56507941D3930BC000596DA /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B56507931D3930BC000596DA /* CoreData.framework */; }; B56507961D3930C1000596DA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B56507951D3930C1000596DA /* Foundation.framework */; }; B56507981D3930CC000596DA /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B56507971D3930CC000596DA /* CoreData.framework */; }; @@ -521,9 +515,9 @@ B5C976E31C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E21C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift */; }; B5C976E41C6C9F9A00B1AF90 /* UnsafeDataTransaction+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E21C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift */; }; B5C976E51C6C9F9B00B1AF90 /* UnsafeDataTransaction+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E21C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift */; }; - B5C976E71C6E3A5A00B1AF90 /* CoreStoreFetchedResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */; }; - B5C976E81C6E3A5D00B1AF90 /* CoreStoreFetchedResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */; }; - B5C976E91C6E3A5E00B1AF90 /* CoreStoreFetchedResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */; }; + B5C976E71C6E3A5A00B1AF90 /* Internals.CoreStoreFetchedResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E61C6E3A5900B1AF90 /* Internals.CoreStoreFetchedResultsController.swift */; }; + B5C976E81C6E3A5D00B1AF90 /* Internals.CoreStoreFetchedResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E61C6E3A5900B1AF90 /* Internals.CoreStoreFetchedResultsController.swift */; }; + B5C976E91C6E3A5E00B1AF90 /* Internals.CoreStoreFetchedResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E61C6E3A5900B1AF90 /* Internals.CoreStoreFetchedResultsController.swift */; }; B5CA2B081F7E5ACA004B1936 /* WhereClauseType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */; }; B5CA2B091F7E5ACA004B1936 /* WhereClauseType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */; }; B5CA2B0A1F7E5ACA004B1936 /* WhereClauseType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */; }; @@ -589,6 +583,14 @@ B5DC47CA1C93D9C800FA3BF3 /* StorageInterfaceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DC47C91C93D9C800FA3BF3 /* StorageInterfaceTests.swift */; }; B5DC47CB1C93D9C800FA3BF3 /* StorageInterfaceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DC47C91C93D9C800FA3BF3 /* StorageInterfaceTests.swift */; }; B5DC47CC1C93D9C800FA3BF3 /* StorageInterfaceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DC47C91C93D9C800FA3BF3 /* StorageInterfaceTests.swift */; }; + B5DE522B230BD7CC00A22534 /* Internals.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DE522A230BD7CC00A22534 /* Internals.swift */; }; + B5DE522C230BD7D500A22534 /* Internals.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DE522A230BD7CC00A22534 /* Internals.swift */; }; + B5DE522D230BD7D600A22534 /* Internals.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DE522A230BD7CC00A22534 /* Internals.swift */; }; + B5DE522E230BD7D600A22534 /* Internals.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DE522A230BD7CC00A22534 /* Internals.swift */; }; + B5DE5230230BDA1300A22534 /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DE522F230BDA1300A22534 /* Shared.swift */; }; + B5DE5231230BDA1300A22534 /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DE522F230BDA1300A22534 /* Shared.swift */; }; + B5DE5232230BDA1300A22534 /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DE522F230BDA1300A22534 /* Shared.swift */; }; + B5DE5233230BDA1300A22534 /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DE522F230BDA1300A22534 /* Shared.swift */; }; B5E1B5931CAA0C15007FD580 /* CSObjectMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1B5921CAA0C15007FD580 /* CSObjectMonitor.swift */; }; B5E1B5951CAA0C15007FD580 /* CSObjectMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1B5921CAA0C15007FD580 /* CSObjectMonitor.swift */; }; B5E1B5961CAA0C15007FD580 /* CSObjectMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1B5921CAA0C15007FD580 /* CSObjectMonitor.swift */; }; @@ -618,7 +620,6 @@ B5E41EC21EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E41EBF1EA9BB37006240F0 /* DynamicSchema+Convenience.swift */; }; B5E41EC31EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E41EBF1EA9BB37006240F0 /* DynamicSchema+Convenience.swift */; }; B5E834B91B76311F001D3D50 /* BaseDataTransaction+Importing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E834B81B76311F001D3D50 /* BaseDataTransaction+Importing.swift */; }; - B5E834BB1B7691F3001D3D50 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E834BA1B7691F3001D3D50 /* Functions.swift */; }; B5E84EDF1AFF84500064E85B /* DataStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84EDB1AFF84500064E85B /* DataStack.swift */; }; B5E84EE61AFF84610064E85B /* DefaultLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84EE31AFF84610064E85B /* DefaultLogger.swift */; }; B5E84EE71AFF84610064E85B /* CoreStore+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84EE41AFF84610064E85B /* CoreStore+Logging.swift */; }; @@ -645,9 +646,9 @@ B5E84F241AFF84860064E85B /* ListObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F1E1AFF84860064E85B /* ListObserver.swift */; }; B5E84F251AFF84860064E85B /* ObjectObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F1F1AFF84860064E85B /* ObjectObserver.swift */; }; B5E84F281AFF84920064E85B /* NSManagedObject+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F271AFF84920064E85B /* NSManagedObject+Convenience.swift */; }; - B5E84F2F1AFF849C0064E85B /* NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */; }; + B5E84F2F1AFF849C0064E85B /* Internals.NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* Internals.NotificationObserver.swift */; }; B5E84F301AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2C1AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift */; }; - B5E84F311AFF849C0064E85B /* WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* WeakObject.swift */; }; + B5E84F311AFF849C0064E85B /* Internals.WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* Internals.WeakObject.swift */; }; B5E84F361AFF85470064E85B /* NSManagedObjectContext+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */; }; B5E84F371AFF85470064E85B /* NSManagedObjectContext+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F331AFF85470064E85B /* NSManagedObjectContext+Transaction.swift */; }; B5E84F391AFF85470064E85B /* NSManagedObjectContext+Querying.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */; }; @@ -707,7 +708,7 @@ B5F1DA8D1B9AA97D007C5CBB /* ImportableObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F1DA8C1B9AA97D007C5CBB /* ImportableObject.swift */; }; B5F1DA901B9AA991007C5CBB /* ImportableUniqueObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F1DA8F1B9AA991007C5CBB /* ImportableUniqueObject.swift */; }; B5FAD6A91B50A4B400714891 /* Progress+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6A81B50A4B300714891 /* Progress+Convenience.swift */; }; - B5FAD6AC1B51285300714891 /* MigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AB1B51285300714891 /* MigrationManager.swift */; }; + B5FAD6AC1B51285300714891 /* Internals.MigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AB1B51285300714891 /* Internals.MigrationManager.swift */; }; B5FAD6AE1B518DCB00714891 /* CoreStore+Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6AD1B518DCB00714891 /* CoreStore+Migration.swift */; }; B5FE4DA21C8481E100FA6A91 /* StorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FE4DA11C8481E100FA6A91 /* StorageInterface.swift */; }; B5FE4DA31C8481E100FA6A91 /* StorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FE4DA11C8481E100FA6A91 /* StorageInterface.swift */; }; @@ -771,7 +772,7 @@ B509C7F31E54511B0061C547 /* ImportableAttributeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportableAttributeType.swift; sourceTree = ""; }; B512607E1E97A18000402229 /* CoreStoreObject+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStoreObject+Convenience.swift"; sourceTree = ""; }; B51260881E9B252B00402229 /* NSEntityDescription+DynamicModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSEntityDescription+DynamicModel.swift"; sourceTree = ""; }; - B51260921E9B28F100402229 /* EntityIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EntityIdentifier.swift; sourceTree = ""; }; + B51260921E9B28F100402229 /* Internals.EntityIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Internals.EntityIdentifier.swift; sourceTree = ""; }; B51B5C2A22D43931009FA3BA /* String+KeyPaths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+KeyPaths.swift"; sourceTree = ""; }; B51B5C2C22D43E38009FA3BA /* KeyPath+KeyPaths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyPath+KeyPaths.swift"; sourceTree = ""; }; B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+CustomDebugStringConvertible.swift"; sourceTree = ""; }; @@ -799,6 +800,7 @@ B52F743C1E9B8724005F3DAC /* XcodeDataModelSchema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeDataModelSchema.swift; sourceTree = ""; }; B52F74491E9B8740005F3DAC /* CoreStoreSchema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreSchema.swift; sourceTree = ""; }; B52FD3A91E3B3EF10001D919 /* NSManagedObject+Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+Logging.swift"; sourceTree = ""; }; + B53304A9230BA4F7007C2BD8 /* DynamicObjectMeta.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicObjectMeta.swift; sourceTree = ""; }; B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+CoreStore.swift"; sourceTree = ""; }; B538BA701D15B3E30003A766 /* CoreStoreBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CoreStoreBridge.m; sourceTree = ""; }; B53B275E1EE3B92E00E9B352 /* CoreStoreManagedObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreManagedObject.swift; sourceTree = ""; }; @@ -808,12 +810,11 @@ B53FBA0A1CAB5E6500F0D40A /* CSCoreStore+Migrating.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSCoreStore+Migrating.swift"; sourceTree = ""; }; B53FBA111CAB63CB00F0D40A /* Progress+ObjectiveC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Progress+ObjectiveC.swift"; sourceTree = ""; }; B53FBA171CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+ObjectiveC.swift"; sourceTree = ""; }; - B53FBA1D1CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFetchedResultsController+ObjectiveC.swift"; sourceTree = ""; }; B546F9571C99B17400D5AC55 /* CSCoreStore+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSCoreStore+Setup.swift"; sourceTree = ""; }; B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSQliteStore.swift; sourceTree = ""; }; B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSInMemoryStore.swift; sourceTree = ""; }; B546F9721C9C553300D5AC55 /* SetupResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupResult.swift; sourceTree = ""; }; - B5474D142227C08700B21FEC /* CoreStoreFetchRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreStoreFetchRequest.swift; sourceTree = ""; }; + B5474D142227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Internals.CoreStoreFetchRequest.swift; sourceTree = ""; }; B5489F3D1CF5EEBC008B4978 /* TestEntity1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestEntity1.swift; sourceTree = ""; }; B5489F3E1CF5EEBC008B4978 /* TestEntity2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestEntity2.swift; sourceTree = ""; }; B5489F451CF5F017008B4978 /* TransactionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionTests.swift; sourceTree = ""; }; @@ -821,7 +822,7 @@ B5489F4F1CF603D5008B4978 /* FromTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FromTests.swift; sourceTree = ""; }; B549F65D1E569C7400FBAB2D /* QueryableAttributeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryableAttributeType.swift; sourceTree = ""; }; B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataNativeType.swift; sourceTree = ""; }; - B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedResultsControllerDelegate.swift; sourceTree = ""; }; + B54A6A541BA15F2A007870FD /* Internals.FetchedResultsControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Internals.FetchedResultsControllerDelegate.swift; sourceTree = ""; }; B5519A3F1CA1B17B002BEF78 /* ErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTests.swift; sourceTree = ""; }; B5519A491CA1F4FB002BEF78 /* CSError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSError.swift; sourceTree = ""; }; B5519A581CA2008C002BEF78 /* CSBaseDataTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSBaseDataTransaction.swift; sourceTree = ""; }; @@ -879,7 +880,7 @@ B5BDC91A1C202269008147CD /* Cartfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Cartfile; path = ../Cartfile; sourceTree = ""; }; B5BDC9271C2024F2008147CD /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = SOURCE_ROOT; }; B5C976E21C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeDataTransaction+Observing.swift"; sourceTree = ""; }; - B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreFetchedResultsController.swift; sourceTree = ""; }; + B5C976E61C6E3A5900B1AF90 /* Internals.CoreStoreFetchedResultsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Internals.CoreStoreFetchedResultsController.swift; sourceTree = ""; }; B5CA2B071F7E5ACA004B1936 /* WhereClauseType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhereClauseType.swift; sourceTree = ""; }; B5CA2B111F81DBFE004B1936 /* KeyPathStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPathStringConvertible.swift; sourceTree = ""; }; B5D1E22B19FA9FBC003B2874 /* CoreStoreError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreError.swift; sourceTree = ""; }; @@ -905,6 +906,8 @@ B5DBE2DE1C9939E100B5CEFA /* BridgingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BridgingTests.m; sourceTree = ""; }; B5DC47C51C93D22900FA3BF3 /* MigrationChainTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationChainTests.swift; sourceTree = ""; }; B5DC47C91C93D9C800FA3BF3 /* StorageInterfaceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StorageInterfaceTests.swift; sourceTree = ""; }; + B5DE522A230BD7CC00A22534 /* Internals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Internals.swift; sourceTree = ""; }; + B5DE522F230BDA1300A22534 /* Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shared.swift; sourceTree = ""; }; B5E1B5921CAA0C15007FD580 /* CSObjectMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSObjectMonitor.swift; sourceTree = ""; }; B5E1B5971CAA0C23007FD580 /* CSObjectObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSObjectObserver.swift; sourceTree = ""; }; B5E1B59C1CAA2568007FD580 /* CSDataStack+Observing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSDataStack+Observing.swift"; sourceTree = ""; }; @@ -914,7 +917,6 @@ B5E222291CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSUnsafeDataTransaction.swift; sourceTree = ""; }; B5E41EBF1EA9BB37006240F0 /* DynamicSchema+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DynamicSchema+Convenience.swift"; sourceTree = ""; }; B5E834B81B76311F001D3D50 /* BaseDataTransaction+Importing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BaseDataTransaction+Importing.swift"; sourceTree = ""; }; - B5E834BA1B7691F3001D3D50 /* Functions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Functions.swift; sourceTree = ""; }; B5E84ED81AFF82360064E85B /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; }; B5E84ED91AFF82360064E85B /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = SOURCE_ROOT; }; B5E84EDB1AFF84500064E85B /* DataStack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataStack.swift; sourceTree = ""; }; @@ -943,9 +945,9 @@ B5E84F1E1AFF84860064E85B /* ListObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListObserver.swift; sourceTree = ""; }; B5E84F1F1AFF84860064E85B /* ObjectObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectObserver.swift; sourceTree = ""; }; B5E84F271AFF84920064E85B /* NSManagedObject+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+Convenience.swift"; sourceTree = ""; }; - B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationObserver.swift; sourceTree = ""; }; + B5E84F2B1AFF849C0064E85B /* Internals.NotificationObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Internals.NotificationObserver.swift; sourceTree = ""; }; B5E84F2C1AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+CoreStore.swift"; sourceTree = ""; }; - B5E84F2D1AFF849C0064E85B /* WeakObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakObject.swift; sourceTree = ""; }; + B5E84F2D1AFF849C0064E85B /* Internals.WeakObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Internals.WeakObject.swift; sourceTree = ""; }; B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+Setup.swift"; sourceTree = ""; }; B5E84F331AFF85470064E85B /* NSManagedObjectContext+Transaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+Transaction.swift"; sourceTree = ""; }; B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+Querying.swift"; sourceTree = ""; }; @@ -966,7 +968,7 @@ B5F1DA8C1B9AA97D007C5CBB /* ImportableObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportableObject.swift; sourceTree = ""; }; B5F1DA8F1B9AA991007C5CBB /* ImportableUniqueObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportableUniqueObject.swift; sourceTree = ""; }; B5FAD6A81B50A4B300714891 /* Progress+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Progress+Convenience.swift"; sourceTree = ""; }; - B5FAD6AB1B51285300714891 /* MigrationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationManager.swift; sourceTree = ""; }; + B5FAD6AB1B51285300714891 /* Internals.MigrationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Internals.MigrationManager.swift; sourceTree = ""; }; B5FAD6AD1B518DCB00714891 /* CoreStore+Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "CoreStore+Migration.swift"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; B5FE4DA11C8481E100FA6A91 /* StorageInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StorageInterface.swift; sourceTree = ""; }; B5FE4DA61C84FB4400FA6A91 /* InMemoryStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InMemoryStore.swift; sourceTree = ""; }; @@ -1207,7 +1209,6 @@ children = ( B53FBA171CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift */, B53FBA111CAB63CB00F0D40A /* Progress+ObjectiveC.swift */, - B53FBA1D1CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift */, ); name = Convenience; sourceTree = ""; @@ -1312,6 +1313,7 @@ isa = PBXGroup; children = ( B5D339D71E9489AB00C880DE /* CoreStoreObject.swift */, + B53304A9230BA4F7007C2BD8 /* DynamicObjectMeta.swift */, B53CA9A11EF1EF1600E0F440 /* PartialObject.swift */, B5831B6E1F3355C300A9F647 /* Properties */, B52F74391E9B8724005F3DAC /* Dynamic Schema */, @@ -1346,6 +1348,7 @@ isa = PBXGroup; children = ( 2F291E2619C6D3CF007AF63F /* CoreStore.swift */, + B5DE522F230BDA1300A22534 /* Shared.swift */, B5D1E22B19FA9FBC003B2874 /* CoreStoreError.swift */, B549F6721E56A92800FBAB2D /* CoreDataNativeType.swift */, B5D339F01E94AF5800C880DE /* CoreStoreStrings.swift */, @@ -1535,16 +1538,16 @@ isa = PBXGroup; children = ( B5831B6F1F34AC3400A9F647 /* AttributeProtocol.swift */, - B5831B741F34AC7A00A9F647 /* RelationshipProtocol.swift */, - B5474D142227C08700B21FEC /* CoreStoreFetchRequest.swift */, - B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */, B53B275E1EE3B92E00E9B352 /* CoreStoreManagedObject.swift */, B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */, - B51260921E9B28F100402229 /* EntityIdentifier.swift */, - B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */, - B5E834BA1B7691F3001D3D50 /* Functions.swift */, - B5FAD6AB1B51285300714891 /* MigrationManager.swift */, - B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */, + B5C976E61C6E3A5900B1AF90 /* Internals.CoreStoreFetchedResultsController.swift */, + B5474D142227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift */, + B51260921E9B28F100402229 /* Internals.EntityIdentifier.swift */, + B54A6A541BA15F2A007870FD /* Internals.FetchedResultsControllerDelegate.swift */, + B5FAD6AB1B51285300714891 /* Internals.MigrationManager.swift */, + B5E84F2B1AFF849C0064E85B /* Internals.NotificationObserver.swift */, + B5DE522A230BD7CC00A22534 /* Internals.swift */, + B5E84F2D1AFF849C0064E85B /* Internals.WeakObject.swift */, B51260881E9B252B00402229 /* NSEntityDescription+DynamicModel.swift */, B56923C31EB823B4007C4DC9 /* NSEntityDescription+Migration.swift */, B58D0C621EAA0C7E003EDD87 /* NSManagedObject+DynamicModel.swift */, @@ -1556,7 +1559,7 @@ B56923C81EB82410007C4DC9 /* NSManagedObjectModel+Migration.swift */, B5FEC18D1C9166E200532541 /* NSPersistentStore+Setup.swift */, B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */, - B5E84F2D1AFF849C0064E85B /* WeakObject.swift */, + B5831B741F34AC7A00A9F647 /* RelationshipProtocol.swift */, ); name = Internal; sourceTree = ""; @@ -1881,10 +1884,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + B5DE5230230BDA1300A22534 /* Shared.swift in Sources */, B5E84F221AFF84860064E85B /* ObjectMonitor.swift in Sources */, B5ECDBF91CA804FD00C7F112 /* NSManagedObjectContext+ObjectiveC.swift in Sources */, B5CA2B081F7E5ACA004B1936 /* WhereClauseType.swift in Sources */, - B5C976E71C6E3A5A00B1AF90 /* CoreStoreFetchedResultsController.swift in Sources */, + B5C976E71C6E3A5A00B1AF90 /* Internals.CoreStoreFetchedResultsController.swift in Sources */, B56923F51EB828BF007C4DC9 /* CSDynamicSchema.swift in Sources */, B5F1DA901B9AA991007C5CBB /* ImportableUniqueObject.swift in Sources */, B51260891E9B252B00402229 /* NSEntityDescription+DynamicModel.swift in Sources */, @@ -1904,13 +1908,14 @@ B52F74411E9B8724005F3DAC /* UnsafeDataModelSchema.swift in Sources */, B51FE5AB1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */, B5A9921F1EA898710091A2E3 /* UserInfo.swift in Sources */, - B54A6A551BA15F2A007870FD /* FetchedResultsControllerDelegate.swift in Sources */, + B54A6A551BA15F2A007870FD /* Internals.FetchedResultsControllerDelegate.swift in Sources */, B5D339E21E948C3600C880DE /* Value.swift in Sources */, B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */, B53FBA0B1CAB5E6500F0D40A /* CSCoreStore+Migrating.swift in Sources */, B5E84F141AFF847B0064E85B /* DataStack+Querying.swift in Sources */, B5D7A5B61CA3BF8F005C752B /* CSInto.swift in Sources */, B56007141B3F6C2800A9A8F9 /* SectionBy.swift in Sources */, + B5DE522B230BD7CC00A22534 /* Internals.swift in Sources */, B5E84F371AFF85470064E85B /* NSManagedObjectContext+Transaction.swift in Sources */, B5ECDC1D1CA81A2100C7F112 /* CSDataStack+Querying.swift in Sources */, B5C976E31C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift in Sources */, @@ -1937,7 +1942,7 @@ B53CA9A21EF1EF1600E0F440 /* PartialObject.swift in Sources */, B56007111B3F6BD500A9A8F9 /* Into.swift in Sources */, B5E84F111AFF847B0064E85B /* Select.swift in Sources */, - B51260931E9B28F100402229 /* EntityIdentifier.swift in Sources */, + B51260931E9B28F100402229 /* Internals.EntityIdentifier.swift in Sources */, B5DAFB482203D9F8003FCCD0 /* Where.Expression.swift in Sources */, B5FE4DA21C8481E100FA6A91 /* StorageInterface.swift in Sources */, B53FB9FE1CAB2D2F00F0D40A /* CSMigrationResult.swift in Sources */, @@ -1948,7 +1953,7 @@ B5519A591CA2008C002BEF78 /* CSBaseDataTransaction.swift in Sources */, B5ECDBDF1CA6BB2B00C7F112 /* CSBaseDataTransaction+Querying.swift in Sources */, B5E84F251AFF84860064E85B /* ObjectObserver.swift in Sources */, - B5E84F2F1AFF849C0064E85B /* NotificationObserver.swift in Sources */, + B5E84F2F1AFF849C0064E85B /* Internals.NotificationObserver.swift in Sources */, B5F1DA8D1B9AA97D007C5CBB /* ImportableObject.swift in Sources */, B56965241B356B820075EE4A /* MigrationResult.swift in Sources */, B5FE4DAC1C85D44E00FA6A91 /* SQLiteStore.swift in Sources */, @@ -1962,14 +1967,14 @@ B5E84F411AFF8CCD0064E85B /* TypeErasedClauses.swift in Sources */, B5E84F0D1AFF847B0064E85B /* BaseDataTransaction+Querying.swift in Sources */, B52F74451E9B8724005F3DAC /* XcodeDataModelSchema.swift in Sources */, - B5FAD6AC1B51285300714891 /* MigrationManager.swift in Sources */, + B5FAD6AC1B51285300714891 /* Internals.MigrationManager.swift in Sources */, B5E84EF61AFF846E0064E85B /* DataStack+Transaction.swift in Sources */, B5FEC18E1C9166E200532541 /* NSPersistentStore+Setup.swift in Sources */, B596BBB61DD5BC67001DCDD9 /* FetchableSource.swift in Sources */, B5E1B5A21CAA4365007FD580 /* CSCoreStore+Observing.swift in Sources */, B5E84EDF1AFF84500064E85B /* DataStack.swift in Sources */, + B53304AA230BA4F7007C2BD8 /* DynamicObjectMeta.swift in Sources */, B59AFF411C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift in Sources */, - B5E834BB1B7691F3001D3D50 /* Functions.swift in Sources */, B5E84F231AFF84860064E85B /* ListMonitor.swift in Sources */, B5E84EF71AFF846E0064E85B /* UnsafeDataTransaction.swift in Sources */, B56964D41B22FFAD0075EE4A /* DataStack+Migration.swift in Sources */, @@ -2001,7 +2006,7 @@ B533C4DB1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */, B559CD491CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B5ECDC2F1CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, - B5E84F311AFF849C0064E85B /* WeakObject.swift in Sources */, + B5E84F311AFF849C0064E85B /* Internals.WeakObject.swift in Sources */, B5E84F101AFF847B0064E85B /* GroupBy.swift in Sources */, B5E84F201AFF84860064E85B /* DataStack+Observing.swift in Sources */, B501FDDD1CA8D05000BE22EF /* CSSectionBy.swift in Sources */, @@ -2012,7 +2017,6 @@ B5E84F301AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift in Sources */, B5831B7A1F34ACBA00A9F647 /* Transformable.swift in Sources */, B546F9691C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */, - B53FBA1E1CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift in Sources */, B549F65E1E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */, B5E84F211AFF84860064E85B /* CoreStore+Observing.swift in Sources */, B559CD431CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, @@ -2021,7 +2025,7 @@ B5FE4DA71C84FB4400FA6A91 /* InMemoryStore.swift in Sources */, B52F743D1E9B8724005F3DAC /* DynamicSchema.swift in Sources */, B5E8A72021C1015300EF006A /* CoreStoreObject+Observing.swift in Sources */, - B5474D152227C08700B21FEC /* CoreStoreFetchRequest.swift in Sources */, + B5474D152227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift in Sources */, B56923FF1EB82976007C4DC9 /* CSUnsafeDataModelSchema.swift in Sources */, B5215CAE1FA4812500139E3A /* SectionMonitorBuilder.swift in Sources */, B5ECDBEC1CA6BF2000C7F112 /* CSFrom.swift in Sources */, @@ -2081,7 +2085,7 @@ 82BA18B61C4BBD3F00A0916E /* DataStack+Querying.swift in Sources */, B5ECDBFB1CA804FD00C7F112 /* NSManagedObjectContext+ObjectiveC.swift in Sources */, B5CA2B091F7E5ACA004B1936 /* WhereClauseType.swift in Sources */, - B5C976E81C6E3A5D00B1AF90 /* CoreStoreFetchedResultsController.swift in Sources */, + B5C976E81C6E3A5D00B1AF90 /* Internals.CoreStoreFetchedResultsController.swift in Sources */, B56923F61EB828BF007C4DC9 /* CSDynamicSchema.swift in Sources */, 82BA18A21C4BBD1D00A0916E /* CoreStoreError.swift in Sources */, B512608A1E9B252B00402229 /* NSEntityDescription+DynamicModel.swift in Sources */, @@ -2089,7 +2093,7 @@ 82BA18AE1C4BBD3100A0916E /* DataStack+Transaction.swift in Sources */, 82BA18AB1C4BBD3100A0916E /* AsynchronousDataTransaction.swift in Sources */, B5D339D91E9489AB00C880DE /* CoreStoreObject.swift in Sources */, - 82BA18CE1C4BBD7100A0916E /* FetchedResultsControllerDelegate.swift in Sources */, + 82BA18CE1C4BBD7100A0916E /* Internals.FetchedResultsControllerDelegate.swift in Sources */, B56923FB1EB82956007C4DC9 /* CSXcodeDataModelSchema.swift in Sources */, B55514EB1EED8BF900BAB888 /* From+Querying.swift in Sources */, B596BBBC1DD5C39F001DCDD9 /* QueryableSource.swift in Sources */, @@ -2125,7 +2129,6 @@ B56923F11EB827F6007C4DC9 /* XcodeSchemaMappingProvider.swift in Sources */, 82BA18A11C4BBD1D00A0916E /* CoreStore.swift in Sources */, B546F9591C99B17400D5AC55 /* CSCoreStore+Setup.swift in Sources */, - 82BA18CF1C4BBD7100A0916E /* Functions.swift in Sources */, 82BA18A31C4BBD2200A0916E /* DataStack.swift in Sources */, 82BA18C81C4BBD5900A0916E /* MigrationChain.swift in Sources */, B546F9741C9C553300D5AC55 /* SetupResult.swift in Sources */, @@ -2133,7 +2136,7 @@ B53CA9A31EF1EF1600E0F440 /* PartialObject.swift in Sources */, 82BA18DD1C4BBE1400A0916E /* NSFetchedResultsController+Convenience.swift in Sources */, B5831F432212700400D8604C /* Where.Expression.swift in Sources */, - B51260941E9B28F100402229 /* EntityIdentifier.swift in Sources */, + B51260941E9B28F100402229 /* Internals.EntityIdentifier.swift in Sources */, B5FE4DA81C84FB4400FA6A91 /* InMemoryStore.swift in Sources */, B53FBA001CAB2D2F00F0D40A /* CSMigrationResult.swift in Sources */, B5DBE2D31C991B3E00B5CEFA /* CSDataStack.swift in Sources */, @@ -2155,7 +2158,8 @@ B5ECDC131CA816E500C7F112 /* CSTweak.swift in Sources */, B56923C51EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, 82BA18C91C4BBD5900A0916E /* MigrationType.swift in Sources */, - 82BA18D01C4BBD7100A0916E /* MigrationManager.swift in Sources */, + 82BA18D01C4BBD7100A0916E /* Internals.MigrationManager.swift in Sources */, + B5DE5231230BDA1300A22534 /* Shared.swift in Sources */, B52F74461E9B8724005F3DAC /* XcodeDataModelSchema.swift in Sources */, 82BA18C61C4BBD5900A0916E /* DataStack+Migration.swift in Sources */, B59851491C90289D00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */, @@ -2165,7 +2169,7 @@ 82BA18B71C4BBD3F00A0916E /* CoreStore+Querying.swift in Sources */, 82BA18AA1C4BBD3100A0916E /* BaseDataTransaction.swift in Sources */, 82BA18A91C4BBD3100A0916E /* Into.swift in Sources */, - 82BA18D11C4BBD7100A0916E /* NotificationObserver.swift in Sources */, + 82BA18D11C4BBD7100A0916E /* Internals.NotificationObserver.swift in Sources */, 82BA18BB1C4BBD4A00A0916E /* Where.swift in Sources */, B5A5F2681CAEC50F004AB9AF /* CSSelect.swift in Sources */, B5D339DE1E9489C700C880DE /* DynamicObject.swift in Sources */, @@ -2185,7 +2189,7 @@ B5AEFAB61C9962AE00AD137F /* CoreStoreBridge.swift in Sources */, B5E2222C1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, 82BA18A71C4BBD2900A0916E /* CoreStore+Logging.swift in Sources */, - 82BA18D81C4BBD7100A0916E /* WeakObject.swift in Sources */, + 82BA18D81C4BBD7100A0916E /* Internals.WeakObject.swift in Sources */, B56923E91EB827F5007C4DC9 /* InferredSchemaMappingProvider.swift in Sources */, B53B27601EE3B92E00E9B352 /* CoreStoreManagedObject.swift in Sources */, B5215CA51FA47DFD00139E3A /* FetchChainBuilder.swift in Sources */, @@ -2196,6 +2200,7 @@ B58D0C641EAA0C7E003EDD87 /* NSManagedObject+DynamicModel.swift in Sources */, B533C4DC1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */, B5ECDC311CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, + B5DE522C230BD7D500A22534 /* Internals.swift in Sources */, 82BA18AF1C4BBD3100A0916E /* CoreStore+Transaction.swift in Sources */, 82BA18CB1C4BBD6400A0916E /* NSManagedObject+Convenience.swift in Sources */, 82BA18B51C4BBD3F00A0916E /* BaseDataTransaction+Querying.swift in Sources */, @@ -2206,7 +2211,6 @@ 82BA18AD1C4BBD3100A0916E /* UnsafeDataTransaction.swift in Sources */, B546F96A1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */, B5831B7B1F34ACBA00A9F647 /* Transformable.swift in Sources */, - B53FBA201CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift in Sources */, 82BA18A81C4BBD2900A0916E /* CoreStoreLogger.swift in Sources */, B549F65F1E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */, B559CD451CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, @@ -2216,7 +2220,7 @@ B5ECDBEE1CA6BF2000C7F112 /* CSFrom.swift in Sources */, B52F743E1E9B8724005F3DAC /* DynamicSchema.swift in Sources */, B5E8A72121C1015300EF006A /* CoreStoreObject+Observing.swift in Sources */, - B5474D162227C08700B21FEC /* CoreStoreFetchRequest.swift in Sources */, + B5474D162227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift in Sources */, B56924001EB82976007C4DC9 /* CSUnsafeDataModelSchema.swift in Sources */, B5215CAF1FA4812500139E3A /* SectionMonitorBuilder.swift in Sources */, 82BA18D61C4BBD7100A0916E /* NSManagedObjectContext+Transaction.swift in Sources */, @@ -2291,7 +2295,7 @@ B546F9601C9A12B800D5AC55 /* CSSQliteStore.swift in Sources */, B5ECDC0F1CA8161B00C7F112 /* CSGroupBy.swift in Sources */, B5ECDC211CA81A2100C7F112 /* CSDataStack+Querying.swift in Sources */, - B52DD1C21BE1F94600949AFE /* MigrationManager.swift in Sources */, + B52DD1C21BE1F94600949AFE /* Internals.MigrationManager.swift in Sources */, B52FD3AD1E3B3EF10001D919 /* NSManagedObject+Logging.swift in Sources */, B52F74441E9B8724005F3DAC /* UnsafeDataModelSchema.swift in Sources */, B5ECDC2D1CA81CC700C7F112 /* CSDataStack+Transaction.swift in Sources */, @@ -2304,7 +2308,7 @@ B52DD1AB1BE1F93900949AFE /* From.swift in Sources */, B546F95B1C99B17400D5AC55 /* CSCoreStore+Setup.swift in Sources */, B52DD1A11BE1F92C00949AFE /* DataStack+Transaction.swift in Sources */, - B5220E1C1D130801009BC71E /* FetchedResultsControllerDelegate.swift in Sources */, + B5220E1C1D130801009BC71E /* Internals.FetchedResultsControllerDelegate.swift in Sources */, B52DD19E1BE1F92C00949AFE /* AsynchronousDataTransaction.swift in Sources */, B5831B781F34AC7A00A9F647 /* RelationshipProtocol.swift in Sources */, B52DD1981BE1F92500949AFE /* CoreStore+Setup.swift in Sources */, @@ -2330,18 +2334,17 @@ B52DD1AD1BE1F93900949AFE /* Where.swift in Sources */, B53FBA1C1CAB63E200F0D40A /* NSManagedObject+ObjectiveC.swift in Sources */, B5831F452212700500D8604C /* Where.Expression.swift in Sources */, - B51260961E9B28F100402229 /* EntityIdentifier.swift in Sources */, + B51260961E9B28F100402229 /* Internals.EntityIdentifier.swift in Sources */, B5ECDBE31CA6BB2B00C7F112 /* CSBaseDataTransaction+Querying.swift in Sources */, B5ECDC031CA80CBA00C7F112 /* CSWhere.swift in Sources */, B52DD1AC1BE1F93900949AFE /* Select.swift in Sources */, B5FE4DAF1C85D44E00FA6A91 /* SQLiteStore.swift in Sources */, B52DD1C71BE1F94600949AFE /* NSManagedObjectContext+Querying.swift in Sources */, B52DD1C81BE1F94600949AFE /* NSManagedObjectContext+Setup.swift in Sources */, - B52DD1C31BE1F94600949AFE /* NotificationObserver.swift in Sources */, + B52DD1C31BE1F94600949AFE /* Internals.NotificationObserver.swift in Sources */, B52DD1A81BE1F93200949AFE /* DataStack+Querying.swift in Sources */, B5220E221D130818009BC71E /* CSSectionBy.swift in Sources */, B52DD1BC1BE1F94000949AFE /* MigrationResult.swift in Sources */, - B5220E231D130826009BC71E /* NSFetchedResultsController+ObjectiveC.swift in Sources */, B52DD19D1BE1F92C00949AFE /* BaseDataTransaction.swift in Sources */, B5220E131D1305ED009BC71E /* SectionBy.swift in Sources */, B559CD4D1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, @@ -2351,6 +2354,7 @@ B52DD1B81BE1F94000949AFE /* DataStack+Migration.swift in Sources */, B5ECDC091CA8138100C7F112 /* CSOrderBy.swift in Sources */, B56923C71EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, + B5DE5233230BDA1300A22534 /* Shared.swift in Sources */, B52DD1A51BE1F92F00949AFE /* ImportableUniqueObject.swift in Sources */, B5E222271CA4E12600BA2E95 /* CSSynchronousDataTransaction.swift in Sources */, B52F74481E9B8724005F3DAC /* XcodeDataModelSchema.swift in Sources */, @@ -2371,9 +2375,8 @@ B5220E211D130816009BC71E /* CSObjectObserver.swift in Sources */, B5D339EF1E9495E500C880DE /* CoreStoreObject+Querying.swift in Sources */, B52DD19F1BE1F92C00949AFE /* SynchronousDataTransaction.swift in Sources */, - B52DD1CB1BE1F94600949AFE /* WeakObject.swift in Sources */, - B52DD1C11BE1F94600949AFE /* Functions.swift in Sources */, - B5220E1A1D130791009BC71E /* CoreStoreFetchedResultsController.swift in Sources */, + B52DD1CB1BE1F94600949AFE /* Internals.WeakObject.swift in Sources */, + B5220E1A1D130791009BC71E /* Internals.CoreStoreFetchedResultsController.swift in Sources */, B5215CAC1FA4810300139E3A /* QueryChainBuilder.swift in Sources */, B53FBA0F1CAB5E6500F0D40A /* CSCoreStore+Migrating.swift in Sources */, B52F744D1E9B8740005F3DAC /* CoreStoreSchema.swift in Sources */, @@ -2391,6 +2394,7 @@ B533C4DE1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */, B5220E141D130614009BC71E /* DataStack+Observing.swift in Sources */, B52DD1A21BE1F92C00949AFE /* CoreStore+Transaction.swift in Sources */, + B5DE522E230BD7D600A22534 /* Internals.swift in Sources */, B5E2222E1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, B5220E191D130761009BC71E /* ListMonitor.swift in Sources */, B5220E181D130711009BC71E /* ObjectObserver.swift in Sources */, @@ -2411,7 +2415,7 @@ B5220E201D130813009BC71E /* CSObjectMonitor.swift in Sources */, B52F74401E9B8724005F3DAC /* DynamicSchema.swift in Sources */, B5E8A72321C1015300EF006A /* CoreStoreObject+Observing.swift in Sources */, - B5474D182227C08700B21FEC /* CoreStoreFetchRequest.swift in Sources */, + B5474D182227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift in Sources */, B56924021EB82976007C4DC9 /* CSUnsafeDataModelSchema.swift in Sources */, B5215CB11FA4812500139E3A /* SectionMonitorBuilder.swift in Sources */, B5220E171D1306DF009BC71E /* UnsafeDataTransaction+Observing.swift in Sources */, @@ -2471,11 +2475,11 @@ B56321A91BD65219006C9394 /* Progress+Convenience.swift in Sources */, B5ECDBFC1CA804FD00C7F112 /* NSManagedObjectContext+ObjectiveC.swift in Sources */, B5CA2B0A1F7E5ACA004B1936 /* WhereClauseType.swift in Sources */, - B5C976E91C6E3A5E00B1AF90 /* CoreStoreFetchedResultsController.swift in Sources */, + B5C976E91C6E3A5E00B1AF90 /* Internals.CoreStoreFetchedResultsController.swift in Sources */, B56923F71EB828BF007C4DC9 /* CSDynamicSchema.swift in Sources */, B56321801BD65216006C9394 /* CoreStoreError.swift in Sources */, B512608B1E9B252B00402229 /* NSEntityDescription+DynamicModel.swift in Sources */, - B56321AD1BD6521C006C9394 /* MigrationManager.swift in Sources */, + B56321AD1BD6521C006C9394 /* Internals.MigrationManager.swift in Sources */, B563219D1BD65216006C9394 /* DataStack+Observing.swift in Sources */, B56321961BD65216006C9394 /* From.swift in Sources */, B5D339DA1E9489AB00C880DE /* CoreStoreObject.swift in Sources */, @@ -2524,7 +2528,7 @@ B5202CFD1C046E8400DED140 /* NSFetchedResultsController+Convenience.swift in Sources */, B5FE4DA91C84FB4400FA6A91 /* InMemoryStore.swift in Sources */, B5831F442212700500D8604C /* Where.Expression.swift in Sources */, - B51260951E9B28F100402229 /* EntityIdentifier.swift in Sources */, + B51260951E9B28F100402229 /* Internals.EntityIdentifier.swift in Sources */, B53FBA011CAB2D2F00F0D40A /* CSMigrationResult.swift in Sources */, B5DBE2D41C991B3E00B5CEFA /* CSDataStack.swift in Sources */, B50392FA1C47963F009900CA /* NSManagedObject+Transaction.swift in Sources */, @@ -2532,7 +2536,7 @@ B5519A5B1CA2008C002BEF78 /* CSBaseDataTransaction.swift in Sources */, B5ECDBE21CA6BB2B00C7F112 /* CSBaseDataTransaction+Querying.swift in Sources */, B56321971BD65216006C9394 /* Select.swift in Sources */, - B56321AB1BD6521C006C9394 /* FetchedResultsControllerDelegate.swift in Sources */, + B56321AB1BD6521C006C9394 /* Internals.FetchedResultsControllerDelegate.swift in Sources */, B563219C1BD65216006C9394 /* SectionBy.swift in Sources */, B56321B21BD6521C006C9394 /* NSManagedObjectContext+Querying.swift in Sources */, B5FE4DA41C8481E100FA6A91 /* StorageInterface.swift in Sources */, @@ -2542,10 +2546,11 @@ B5E41EC21EA9BB37006240F0 /* DynamicSchema+Convenience.swift in Sources */, B5ECDC141CA816E500C7F112 /* CSTweak.swift in Sources */, B5A1DACA1F111BFA003CF369 /* KeyPath+Querying.swift in Sources */, - B56321AE1BD6521C006C9394 /* NotificationObserver.swift in Sources */, + B56321AE1BD6521C006C9394 /* Internals.NotificationObserver.swift in Sources */, B56321931BD65216006C9394 /* DataStack+Querying.swift in Sources */, B56923C61EB823B4007C4DC9 /* NSEntityDescription+Migration.swift in Sources */, B56321A71BD65216006C9394 /* MigrationResult.swift in Sources */, + B5DE5232230BDA1300A22534 /* Shared.swift in Sources */, B598514A1C90289E00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */, B52F74471E9B8724005F3DAC /* XcodeDataModelSchema.swift in Sources */, B5FEC1901C9166E700532541 /* NSPersistentStore+Setup.swift in Sources */, @@ -2575,7 +2580,7 @@ B5AEFAB71C9962AE00AD137F /* CoreStoreBridge.swift in Sources */, B5E2222D1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, B563219F1BD65216006C9394 /* ObjectMonitor.swift in Sources */, - B56321B61BD6521C006C9394 /* WeakObject.swift in Sources */, + B56321B61BD6521C006C9394 /* Internals.WeakObject.swift in Sources */, B56923EA1EB827F5007C4DC9 /* InferredSchemaMappingProvider.swift in Sources */, B53B27611EE3B92E00E9B352 /* CoreStoreManagedObject.swift in Sources */, B5215CA61FA47DFD00139E3A /* FetchChainBuilder.swift in Sources */, @@ -2586,7 +2591,7 @@ B58D0C651EAA0C7E003EDD87 /* NSManagedObject+DynamicModel.swift in Sources */, B533C4DD1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */, B5ECDC321CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, - B56321AC1BD6521C006C9394 /* Functions.swift in Sources */, + B5DE522D230BD7D600A22534 /* Internals.swift in Sources */, B56321851BD65216006C9394 /* CoreStore+Logging.swift in Sources */, B56321921BD65216006C9394 /* BaseDataTransaction+Querying.swift in Sources */, B501FDE01CA8D05000BE22EF /* CSSectionBy.swift in Sources */, @@ -2596,7 +2601,6 @@ B563218D1BD65216006C9394 /* CoreStore+Transaction.swift in Sources */, B546F96B1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */, B5831B7C1F34ACBA00A9F647 /* Transformable.swift in Sources */, - B53FBA211CAB63FA00F0D40A /* NSFetchedResultsController+ObjectiveC.swift in Sources */, B563218B1BD65216006C9394 /* UnsafeDataTransaction.swift in Sources */, B549F6601E569C7400FBAB2D /* QueryableAttributeType.swift in Sources */, B559CD461CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, @@ -2606,7 +2610,7 @@ B5ECDBEF1CA6BF2000C7F112 /* CSFrom.swift in Sources */, B52F743F1E9B8724005F3DAC /* DynamicSchema.swift in Sources */, B5E8A72221C1015300EF006A /* CoreStoreObject+Observing.swift in Sources */, - B5474D172227C08700B21FEC /* CoreStoreFetchRequest.swift in Sources */, + B5474D172227C08700B21FEC /* Internals.CoreStoreFetchRequest.swift in Sources */, B56924011EB82976007C4DC9 /* CSUnsafeDataModelSchema.swift in Sources */, B5215CB01FA4812500139E3A /* SectionMonitorBuilder.swift in Sources */, B56321B41BD6521C006C9394 /* NSManagedObjectContext+Transaction.swift in Sources */, diff --git a/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift b/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift index 742b5e9..19cb387 100644 --- a/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift @@ -31,7 +31,7 @@ class CustomLoggerViewController: UIViewController, CoreStoreLogger { super.viewDidAppear(animated) - CoreStore.logger = self + Shared.logger = self let alert = UIAlertController( title: "Logger Demo", @@ -46,7 +46,7 @@ class CustomLoggerViewController: UIViewController, CoreStoreLogger { super.viewDidDisappear(animated) - CoreStore.logger = DefaultLogger() + Shared.logger = DefaultLogger() } diff --git a/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift index e665855..3ab191e 100644 --- a/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift @@ -15,10 +15,12 @@ import CoreStore private struct Static { - + + static let dataStack = DataStack() + static let placeController: ObjectMonitor = { - try! CoreStore.addStorageAndWait( + try! Static.dataStack.addStorageAndWait( SQLiteStore( fileName: "PlaceDemo.sqlite", configuration: "TransactionsDemo", @@ -26,20 +28,20 @@ private struct Static { ) ) - var place = try! CoreStore.fetchOne(From()) + var place = try! Static.dataStack.fetchOne(From()) if place == nil { - _ = try? CoreStore.perform( + _ = try? Static.dataStack.perform( synchronous: { (transaction) in let place = transaction.create(Into()) place.setInitialValues() } ) - place = try! CoreStore.fetchOne(From()) + place = try! Static.dataStack.fetchOne(From()) } - return CoreStore.monitorObject(place!) + return Static.dataStack.monitorObject(place!) }() } @@ -170,7 +172,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec gesture.location(in: mapView), toCoordinateFrom: mapView ) - CoreStore.perform( + Static.dataStack.perform( asynchronous: { (transaction) in let place = transaction.edit(Static.placeController.object) @@ -183,7 +185,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec @IBAction dynamic func refreshButtonTapped(_ sender: AnyObject?) { - _ = try? CoreStore.perform( + _ = try? Static.dataStack.perform( synchronous: { (transaction) in let place = transaction.edit(Static.placeController.object) @@ -194,7 +196,7 @@ class TransactionsDemoViewController: UIViewController, MKMapViewDelegate, Objec func geocode(place: Place) { - let transaction = CoreStore.beginUnsafe() + let transaction = Static.dataStack.beginUnsafe() self.geocoder?.cancelGeocode() diff --git a/CoreStoreTests/BaseTests/BaseTestCase.swift b/CoreStoreTests/BaseTests/BaseTestCase.swift index b7be0a5..a798db0 100644 --- a/CoreStoreTests/BaseTests/BaseTestCase.swift +++ b/CoreStoreTests/BaseTests/BaseTestCase.swift @@ -67,11 +67,11 @@ class BaseTestCase: XCTestCase { @nonobjc func expectLogger(_ expectations: [TestLogger.Expectation], closure: () throws -> T) rethrows -> T { - CoreStore.logger = TestLogger(self.prepareLoggerExpectations(expectations)) + Shared.logger = TestLogger(self.prepareLoggerExpectations(expectations)) defer { self.checkExpectationsImmediately() - CoreStore.logger = TestLogger([:]) + Shared.logger = TestLogger([:]) } return try closure() } @@ -79,17 +79,17 @@ class BaseTestCase: XCTestCase { @nonobjc func expectLogger(_ expectations: [TestLogger.Expectation: XCTestExpectation]) { - CoreStore.logger = TestLogger(expectations) + Shared.logger = TestLogger(expectations) } @nonobjc func expectError(code: CoreStoreErrorCode, closure: () throws -> T) { - CoreStore.logger = TestLogger(self.prepareLoggerExpectations([.logError])) + Shared.logger = TestLogger(self.prepareLoggerExpectations([.logError])) defer { self.checkExpectationsImmediately() - CoreStore.logger = TestLogger([:]) + Shared.logger = TestLogger([:]) } do { @@ -105,7 +105,7 @@ class BaseTestCase: XCTestCase { } catch { - XCTFail("Error not wrapped as \(cs_typeName(CoreStoreError.self)): \((error as NSError).coreStoreDumpString)") + XCTFail("Error not wrapped as \(Internals.typeName(CoreStoreError.self)): \((error as NSError).coreStoreDumpString)") } } @@ -138,12 +138,12 @@ class BaseTestCase: XCTestCase { super.setUp() self.deleteStores() - CoreStore.logger = TestLogger([:]) + Shared.logger = TestLogger([:]) } override func tearDown() { - CoreStore.logger = DefaultLogger() + Shared.logger = DefaultLogger() self.deleteStores() super.tearDown() } diff --git a/CoreStoreTests/BaseTests/BaseTestDataTestCase.swift b/CoreStoreTests/BaseTests/BaseTestDataTestCase.swift index 8b41f5b..f478b2d 100644 --- a/CoreStoreTests/BaseTests/BaseTestDataTestCase.swift +++ b/CoreStoreTests/BaseTests/BaseTestDataTestCase.swift @@ -34,7 +34,7 @@ import CoreStore class BaseTestDataTestCase: BaseTestCase { @nonobjc - let dateFormatter: DateFormatter = cs_lazy { + let dateFormatter: DateFormatter = Internals.with { let formatter = DateFormatter() formatter.locale = Locale(identifier: "en_US_POSIX") diff --git a/CoreStoreTests/BridgingTests.m b/CoreStoreTests/BridgingTests.m index 7150ffc..8ed7650 100644 --- a/CoreStoreTests/BridgingTests.m +++ b/CoreStoreTests/BridgingTests.m @@ -168,14 +168,8 @@ versionChain:nil]; XCTAssertNotNil(dataStack); - [CSCoreStore setDefaultStack:dataStack]; - XCTAssertTrue([dataStack isEqual:[CSCoreStore defaultStack]]); -} - -- (void)test_ThatStorages_BridgeCorrectly { - NSError *memoryError; - CSInMemoryStore *memoryStorage = [CSCoreStore + CSInMemoryStore *memoryStorage = [dataStack addInMemoryStorageAndWait:[CSInMemoryStore new] error:&memoryError]; XCTAssertNotNil(memoryStorage); @@ -186,7 +180,7 @@ XCTAssertNil(memoryError); NSError *sqliteError; - CSSQLiteStore *sqliteStorage = [CSCoreStore + CSSQLiteStore *sqliteStorage = [dataStack addSQLiteStorageAndWait:[CSSQLiteStore new] error:&sqliteError]; XCTAssertNotNil(sqliteStorage); @@ -208,18 +202,19 @@ } - (void)test_ThatTransactions_BridgeCorrectly { - - [CSCoreStore - setDefaultStack:[[CSDataStack alloc] - initWithXcodeModelName:@"Model" - bundle:[NSBundle bundleForClass:[self class]] - versionChain:nil]]; - [CSCoreStore + + CSDataStack *dataStack = [[CSDataStack alloc] + initWithXcodeModelName:@"Model" + bundle:[NSBundle bundleForClass:[self class]] + versionChain:nil]; + XCTAssertNotNil(dataStack); + + [dataStack addInMemoryStorageAndWait:[CSInMemoryStore new] error:nil]; { - CSUnsafeDataTransaction *transaction = [CSCoreStore beginUnsafe]; + CSUnsafeDataTransaction *transaction = [dataStack beginUnsafe]; XCTAssertNotNil(transaction); XCTAssert([transaction isKindOfClass:[CSUnsafeDataTransaction class]]); NSError *error; @@ -230,23 +225,24 @@ { XCTestExpectation *expectation = [self expectationWithDescription:@"sync"]; NSError *error; - BOOL result = [CSCoreStore + BOOL result = + [dataStack beginSynchronous:^(CSSynchronousDataTransaction * _Nonnull transaction) { - - XCTAssertNotNil(transaction); - XCTAssert([transaction isKindOfClass:[CSSynchronousDataTransaction class]]); - NSError *error; - XCTAssertTrue([transaction commitAndWaitWithError:&error]); - XCTAssertNil(error); - [expectation fulfill]; - } - error:&error]; + + XCTAssertNotNil(transaction); + XCTAssert([transaction isKindOfClass:[CSSynchronousDataTransaction class]]); + NSError *error; + XCTAssertTrue([transaction commitAndWaitWithError:&error]); + XCTAssertNil(error); + [expectation fulfill]; + } + error:&error]; XCTAssertTrue(result); XCTAssertNil(error); } { XCTestExpectation *expectation = [self expectationWithDescription:@"async"]; - [CSCoreStore beginAsynchronous:^(CSAsynchronousDataTransaction * _Nonnull transaction) { + [dataStack beginAsynchronous:^(CSAsynchronousDataTransaction * _Nonnull transaction) { XCTAssertNotNil(transaction); XCTAssert([transaction isKindOfClass:[CSAsynchronousDataTransaction class]]); diff --git a/CoreStoreTests/DynamicModelTests.swift b/CoreStoreTests/DynamicModelTests.swift index 8eb798d..530d555 100644 --- a/CoreStoreTests/DynamicModelTests.swift +++ b/CoreStoreTests/DynamicModelTests.swift @@ -170,6 +170,19 @@ class DynamicModelTests: BaseTestDataTestCase { XCTAssertEqual(dog.nickname.value, nil) XCTAssertEqual(dog.age.value, 1) + #if swift(>=5.1) + + let dogKeyPathBuilder = Dog.keyPathBuilder() + XCTAssertEqual(dogKeyPathBuilder.species.keyPathString, "SELF.species") + XCTAssertEqual(dogKeyPathBuilder.master.title.keyPathString, "SELF.master.title") + let a = dogKeyPathBuilder.master + let b = dogKeyPathBuilder.master.spouse + let c = dogKeyPathBuilder.master.spouse.pets + let d = dogKeyPathBuilder.master.spouse.pets.color + XCTAssertEqual(dogKeyPathBuilder.master.spouse.pets.color.keyPathString, "SELF.master.spouse.pets.color") + + #endif + let didSetObserver = dog.species.observe(options: [.new, .old]) { (object, change) in XCTAssertEqual(object, dog) @@ -213,7 +226,7 @@ class DynamicModelTests: BaseTestDataTestCase { XCTAssertTrue(person.pets.value.isEmpty) XCTAssertEqual( - cs_dynamicType(of: person.rawObject!).keyPathsForValuesAffectingValue(forKey: "displayName"), + Internals.dynamicObjectType(of: person.rawObject!).keyPathsForValuesAffectingValue(forKey: "displayName"), ["title", "name"] ) diff --git a/CoreStoreTests/FromTests.swift b/CoreStoreTests/FromTests.swift index a36cb50..2459f6a 100644 --- a/CoreStoreTests/FromTests.swift +++ b/CoreStoreTests/FromTests.swift @@ -74,7 +74,7 @@ final class FromTests: BaseTestCase { let from = From() - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores()) @@ -88,7 +88,7 @@ final class FromTests: BaseTestCase { let from = From("Config1") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -113,7 +113,7 @@ final class FromTests: BaseTestCase { let from = From() - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) @@ -128,7 +128,7 @@ final class FromTests: BaseTestCase { let from = From("Config1") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) @@ -143,7 +143,7 @@ final class FromTests: BaseTestCase { let from = From("Config2") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -160,7 +160,7 @@ final class FromTests: BaseTestCase { let from = From() - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -177,7 +177,7 @@ final class FromTests: BaseTestCase { let from = From("Config1") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -194,7 +194,7 @@ final class FromTests: BaseTestCase { let from = From("Config2") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -219,7 +219,7 @@ final class FromTests: BaseTestCase { let from = From() - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) @@ -234,7 +234,7 @@ final class FromTests: BaseTestCase { let from = From("Config1") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) @@ -249,7 +249,7 @@ final class FromTests: BaseTestCase { let from = From("Config2") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -266,7 +266,7 @@ final class FromTests: BaseTestCase { let from = From() - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) @@ -281,7 +281,7 @@ final class FromTests: BaseTestCase { let from = From("Config1") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -298,7 +298,7 @@ final class FromTests: BaseTestCase { let from = From("Config2") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -323,7 +323,7 @@ final class FromTests: BaseTestCase { let from = From() - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) @@ -338,7 +338,7 @@ final class FromTests: BaseTestCase { let from = From("Config1") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) @@ -353,7 +353,7 @@ final class FromTests: BaseTestCase { let from = From("Config2") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -370,7 +370,7 @@ final class FromTests: BaseTestCase { let from = From() - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) @@ -385,7 +385,7 @@ final class FromTests: BaseTestCase { let from = From("Config1") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() self.expectError(code: .persistentStoreNotFound) { try from.applyToFetchRequest(request, context: dataStack.mainContext) @@ -402,7 +402,7 @@ final class FromTests: BaseTestCase { let from = From("Config2") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) diff --git a/CoreStoreTests/GroupByTests.swift b/CoreStoreTests/GroupByTests.swift index af82cae..0948443 100644 --- a/CoreStoreTests/GroupByTests.swift +++ b/CoreStoreTests/GroupByTests.swift @@ -68,7 +68,7 @@ final class GroupByTests: BaseTestCase { let groupBy = GroupBy(#keyPath(TestEntity1.testString)) - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() try From().applyToFetchRequest(request, context: dataStack.mainContext) groupBy.applyToFetchRequest(request) diff --git a/CoreStoreTests/OrderByTests.swift b/CoreStoreTests/OrderByTests.swift index 56599bf..ef114b2 100644 --- a/CoreStoreTests/OrderByTests.swift +++ b/CoreStoreTests/OrderByTests.swift @@ -179,7 +179,7 @@ final class OrderByTests: XCTestCase { dynamic func test_ThatOrderByClauses_ApplyToFetchRequestsCorrectly() { let orderBy = OrderBy(.ascending("key")) - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() orderBy.applyToFetchRequest(request) XCTAssertNotNil(request.sortDescriptors) XCTAssertEqual(request.sortDescriptors ?? [], orderBy.sortDescriptors) diff --git a/CoreStoreTests/SetupTests.swift b/CoreStoreTests/SetupTests.swift index b053c00..fcbc543 100644 --- a/CoreStoreTests/SetupTests.swift +++ b/CoreStoreTests/SetupTests.swift @@ -56,9 +56,6 @@ class SetupTests: BaseTestDataTestCase { XCTAssertTrue(stack.schemaHistory.migrationChain.isEmpty) XCTAssertTrue(stack.schemaHistory.migrationChain.rootVersions.isEmpty) XCTAssertTrue(stack.schemaHistory.migrationChain.leafVersions.isEmpty) - - CoreStore.defaultStack = stack - XCTAssertEqual(CoreStore.defaultStack, stack) } do { @@ -74,9 +71,6 @@ class SetupTests: BaseTestDataTestCase { } XCTAssertEqual(stack.modelVersion, "Model") XCTAssertEqual(stack.schemaHistory.migrationChain, migrationChain) - - CoreStore.defaultStack = stack - XCTAssertEqual(CoreStore.defaultStack, stack) } } diff --git a/CoreStoreTests/TweakTests.swift b/CoreStoreTests/TweakTests.swift index d4ea885..4aac503 100644 --- a/CoreStoreTests/TweakTests.swift +++ b/CoreStoreTests/TweakTests.swift @@ -43,7 +43,7 @@ final class TweakTests: XCTestCase { $0.fetchLimit = 200 $0.predicate = predicate } - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() tweak.applyToFetchRequest(request) XCTAssertEqual(request.fetchOffset, 100) XCTAssertEqual(request.fetchLimit, 200) diff --git a/CoreStoreTests/WhereTests.swift b/CoreStoreTests/WhereTests.swift index 29f4ac5..da7aaaf 100644 --- a/CoreStoreTests/WhereTests.swift +++ b/CoreStoreTests/WhereTests.swift @@ -47,6 +47,17 @@ private func XCTAssertAllEqual(_ whereClauses: [Where]) { } } +private func XCTAssertAllEqual(_ items: D...) { + + for i in items.indices { + + for j in items.indices where j != i { + + XCTAssertEqual(items[i], items[j]) + } + } +} + //MARK: - WhereTests @@ -55,8 +66,8 @@ final class WhereTests: XCTestCase { @objc dynamic func test_ThatDynamicModelKeyPaths_CanBeCreated() { - XCTAssertEqual(String(keyPath: \TestEntity1.testEntityID), "testEntityID") - XCTAssertEqual(String(keyPath: \Animal.color), "color") + XCTAssertAllEqual(String(keyPath: \TestEntity1.testEntityID), "testEntityID") + XCTAssertAllEqual(String(keyPath: \Animal.color), "color") } @objc @@ -66,17 +77,24 @@ final class WhereTests: XCTestCase { do { - XCTAssertEqual( +// let keyPathBuilder = TestEntity1.keyPathBuilder() + +// let kp = \TestEntity1.testToOne +// print(keyPathBuilder.testString) +// print(keyPathBuilder.testToOne) +// print(keyPathBuilder.testToOne.testEntityID) + XCTAssertAllEqual( #keyPath(TestEntity1.testToOne.testEntityID), (\TestEntity1.testToOne ~ \.testEntityID).description, String(keyPath: \TestEntity1.testToOne ~ \.testEntityID) +// keyPathBuilder.testToOne.testEntityID.keyPathString ) - XCTAssertEqual( + XCTAssertAllEqual( #keyPath(TestEntity1.testToOne.testToOne.testToManyUnordered), (\TestEntity1.testToOne ~ \.testToOne ~ \.testToManyUnordered).description, String(keyPath: \TestEntity1.testToOne ~ \.testToOne ~ \.testToManyUnordered) ) - XCTAssertEqual( + XCTAssertAllEqual( #keyPath(TestEntity2.testToOne.testToOne.testToManyOrdered), (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).description, String(keyPath: \TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered) @@ -84,17 +102,17 @@ final class WhereTests: XCTestCase { } do { - XCTAssertEqual( + XCTAssertAllEqual( "master.pets", (\Animal.master ~ \.pets).description, String(keyPath: \Animal.master ~ \.pets) ) - XCTAssertEqual( + XCTAssertAllEqual( "master.pets.species", (\Animal.master ~ \.pets ~ \.species).description, String(keyPath: \Animal.master ~ \.pets ~ \.species) ) - XCTAssertEqual( + XCTAssertAllEqual( "master.pets.master", (\Animal.master ~ \.pets ~ \.master).description, String(keyPath: \Animal.master ~ \.pets ~ \.master) @@ -105,12 +123,12 @@ final class WhereTests: XCTestCase { do { - XCTAssertEqual( + XCTAssertAllEqual( #keyPath(TestEntity1.testToOne.testToManyUnordered) + ".@count", (\TestEntity1.testToOne ~ \.testToManyUnordered).count().description, String(keyPath: (\TestEntity1.testToOne ~ \.testToManyUnordered).count()) ) - XCTAssertEqual( + XCTAssertAllEqual( #keyPath(TestEntity2.testToOne.testToOne.testToManyOrdered) + ".@count", (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).count().description, String(keyPath: (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).count()) @@ -118,7 +136,7 @@ final class WhereTests: XCTestCase { } do { - XCTAssertEqual( + XCTAssertAllEqual( "master.pets.@count", (\Animal.master ~ \.pets).count().description, String(keyPath: (\Animal.master ~ \.pets).count()) @@ -129,12 +147,12 @@ final class WhereTests: XCTestCase { do { - XCTAssertEqual( + XCTAssertAllEqual( "ANY " + #keyPath(TestEntity1.testToOne.testToManyUnordered), (\TestEntity1.testToOne ~ \.testToManyUnordered).any().description, String(keyPath: (\TestEntity1.testToOne ~ \.testToManyUnordered).any()) ) - XCTAssertEqual( + XCTAssertAllEqual( "ANY " + #keyPath(TestEntity2.testToOne.testToOne.testToManyOrdered), (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).any().description, String(keyPath: (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).any()) @@ -142,12 +160,12 @@ final class WhereTests: XCTestCase { } do { - XCTAssertEqual( + XCTAssertAllEqual( "ANY master.pets", (\Animal.master ~ \.pets).any().description, String(keyPath: (\Animal.master ~ \.pets).any()) ) - XCTAssertEqual( + XCTAssertAllEqual( "ANY master.pets.species", (\Animal.master ~ \.pets ~ \.species).any().description, String(keyPath: (\Animal.master ~ \.pets ~ \.species).any()) @@ -158,12 +176,12 @@ final class WhereTests: XCTestCase { do { - XCTAssertEqual( + XCTAssertAllEqual( "ALL " + #keyPath(TestEntity1.testToOne.testToManyUnordered), (\TestEntity1.testToOne ~ \.testToManyUnordered).all().description, String(keyPath: (\TestEntity1.testToOne ~ \.testToManyUnordered).all()) ) - XCTAssertEqual( + XCTAssertAllEqual( "ALL " + #keyPath(TestEntity2.testToOne.testToOne.testToManyOrdered), (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).all().description, String(keyPath: (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).all()) @@ -171,12 +189,12 @@ final class WhereTests: XCTestCase { } do { - XCTAssertEqual( + XCTAssertAllEqual( "ALL master.pets", (\Animal.master ~ \.pets).all().description, String(keyPath: (\Animal.master ~ \.pets).all()) ) - XCTAssertEqual( + XCTAssertAllEqual( "ALL master.pets.species", (\Animal.master ~ \.pets ~ \.species).all().description, String(keyPath: (\Animal.master ~ \.pets ~ \.species).all()) @@ -187,12 +205,12 @@ final class WhereTests: XCTestCase { do { - XCTAssertEqual( + XCTAssertAllEqual( "NONE " + #keyPath(TestEntity1.testToOne.testToManyUnordered), (\TestEntity1.testToOne ~ \.testToManyUnordered).none().description, String(keyPath: (\TestEntity1.testToOne ~ \.testToManyUnordered).none()) ) - XCTAssertEqual( + XCTAssertAllEqual( "NONE " + #keyPath(TestEntity2.testToOne.testToOne.testToManyOrdered), (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).none().description, String(keyPath: (\TestEntity2.testToOne ~ \.testToOne ~ \.testToManyOrdered).none()) @@ -200,12 +218,12 @@ final class WhereTests: XCTestCase { } do { - XCTAssertEqual( + XCTAssertAllEqual( "NONE master.pets", (\Animal.master ~ \.pets).none().description, String(keyPath: (\Animal.master ~ \.pets).none()) ) - XCTAssertEqual( + XCTAssertAllEqual( "NONE master.pets.species", (\Animal.master ~ \.pets ~ \.species).none().description, String(keyPath: (\Animal.master ~ \.pets ~ \.species).none()) @@ -224,15 +242,15 @@ final class WhereTests: XCTestCase { let whereClause: Where = (\.testToOne ~ \.testString) == dummy let predicate = NSPredicate(format: "\(#keyPath(TestEntity1.testToOne.testString)) == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause: Where = (\.master ~ \.name) == dummy let predicate = NSPredicate(format: "master.name == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } } do { @@ -242,15 +260,15 @@ final class WhereTests: XCTestCase { let whereClause: Where = (\.testToOne ~ \.testToOne ~ \.testString) == dummy let predicate = NSPredicate(format: "\(#keyPath(TestEntity1.testToOne.testToOne.testString)) == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause: Where = (\.master ~ \.spouse ~ \.name) == dummy let predicate = NSPredicate(format: "master.spouse.name == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } } do { @@ -260,15 +278,15 @@ final class WhereTests: XCTestCase { let whereClause: Where = (\.testToOne ~ \.testToManyUnordered).count() == count let predicate = NSPredicate(format: "\(#keyPath(TestEntity1.testToOne.testToManyUnordered)).@count == %d", count) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause: Where = (\.master ~ \.pets).count() == count let predicate = NSPredicate(format: "master.pets.@count == %d", count) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } } do { @@ -278,15 +296,15 @@ final class WhereTests: XCTestCase { let whereClause: Where = (\.testToOne ~ \.testToManyUnordered ~ \TestEntity1.testString).any() == dummy let predicate = NSPredicate(format: "ANY \(#keyPath(TestEntity1.testToOne.testToManyUnordered)).\(#keyPath(TestEntity1.testString)) == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause: Where = (\.master ~ \.pets ~ \.species).any() == dummy let predicate = NSPredicate(format: "ANY master.pets.species == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } } do { @@ -296,15 +314,15 @@ final class WhereTests: XCTestCase { let whereClause: Where = (\.testToOne ~ \.testToManyUnordered ~ \TestEntity1.testString).all() == dummy let predicate = NSPredicate(format: "ALL \(#keyPath(TestEntity1.testToOne.testToManyUnordered)).\(#keyPath(TestEntity1.testString)) == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause: Where = (\.master ~ \.pets ~ \.species).all() == dummy let predicate = NSPredicate(format: "ALL master.pets.species == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } } do { @@ -314,15 +332,15 @@ final class WhereTests: XCTestCase { let whereClause: Where = (\.testToOne ~ \.testToManyUnordered ~ \TestEntity1.testString).none() == dummy let predicate = NSPredicate(format: "NONE \(#keyPath(TestEntity1.testToOne.testToManyUnordered)).\(#keyPath(TestEntity1.testString)) == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause: Where = (\.master ~ \.pets ~ \.species).none() == dummy let predicate = NSPredicate(format: "NONE master.pets.species == %@", dummy) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } } } @@ -333,51 +351,51 @@ final class WhereTests: XCTestCase { do { let whereClause = Where() - XCTAssertEqual(whereClause, Where(true)) + XCTAssertAllEqual(whereClause, Where(true)) XCTAssertNotEqual(whereClause, Where(false)) - XCTAssertEqual(whereClause.predicate, NSPredicate(value: true)) + XCTAssertAllEqual(whereClause.predicate, NSPredicate(value: true)) } do { let whereClause = Where(true) - XCTAssertEqual(whereClause, Where()) + XCTAssertAllEqual(whereClause, Where()) XCTAssertNotEqual(whereClause, Where(false)) - XCTAssertEqual(whereClause.predicate, NSPredicate(value: true)) + XCTAssertAllEqual(whereClause.predicate, NSPredicate(value: true)) } do { let predicate = NSPredicate(format: "%K == %@", "key", "value") let whereClause = Where(predicate) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause = Where("%K == %@", "key", "value") let predicate = NSPredicate(format: "%K == %@", "key", "value") - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause = Where("%K == %@", argumentArray: ["key", "value"]) let predicate = NSPredicate(format: "%K == %@", "key", "value") - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause = Where("key", isEqualTo: "value") let predicate = NSPredicate(format: "%K == %@", "key", "value") - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } do { let whereClause = Where("key", isMemberOf: ["value1", "value2", "value3"]) let predicate = NSPredicate(format: "%K IN %@", "key", ["value1", "value2", "value3"]) - XCTAssertEqual(whereClause, Where(predicate)) - XCTAssertEqual(whereClause.predicate, predicate) + XCTAssertAllEqual(whereClause, Where(predicate)) + XCTAssertAllEqual(whereClause.predicate, predicate) } } @@ -512,8 +530,8 @@ final class WhereTests: XCTestCase { type: .not, subpredicates: [whereClause1.predicate] ) - XCTAssertEqual(notWhere.predicate, notPredicate) - XCTAssertEqual(notWhere, !whereClause1) + XCTAssertAllEqual(notWhere.predicate, notPredicate) + XCTAssertAllEqual(notWhere, !whereClause1) } do { @@ -528,8 +546,8 @@ final class WhereTests: XCTestCase { whereClause3.predicate ] ) - XCTAssertEqual(andWhere.predicate, andPredicate) - XCTAssertEqual(andWhere, whereClause1 && whereClause2 && whereClause3) + XCTAssertAllEqual(andWhere.predicate, andPredicate) + XCTAssertAllEqual(andWhere, whereClause1 && whereClause2 && whereClause3) } do { @@ -543,8 +561,8 @@ final class WhereTests: XCTestCase { let unwrappedFinalSomeWhere = andWhere && someWhere! - XCTAssertEqual(andWhere.predicate, finalNoneWhere.predicate) - XCTAssertEqual(finalSomeWhere.predicate, unwrappedFinalSomeWhere.predicate) + XCTAssertAllEqual(andWhere.predicate, finalNoneWhere.predicate) + XCTAssertAllEqual(finalSomeWhere.predicate, unwrappedFinalSomeWhere.predicate) } do { @@ -559,8 +577,8 @@ final class WhereTests: XCTestCase { whereClause3.predicate ] ) - XCTAssertEqual(orWhere.predicate, orPredicate) - XCTAssertEqual(orWhere, whereClause1 || whereClause2 || whereClause3) + XCTAssertAllEqual(orWhere.predicate, orPredicate) + XCTAssertAllEqual(orWhere, whereClause1 || whereClause2 || whereClause3) } do { @@ -573,8 +591,8 @@ final class WhereTests: XCTestCase { let finalSomeWhere = orWhere &&? someWhere let unwrappedFinalSomeWhere = orWhere && someWhere! - XCTAssertEqual(orWhere.predicate, finalNoneWhere.predicate) - XCTAssertEqual(finalSomeWhere.predicate, unwrappedFinalSomeWhere.predicate) + XCTAssertAllEqual(orWhere.predicate, finalNoneWhere.predicate) + XCTAssertAllEqual(finalSomeWhere.predicate, unwrappedFinalSomeWhere.predicate) } } @@ -583,9 +601,9 @@ final class WhereTests: XCTestCase { dynamic func test_ThatWhereClauses_ApplyToFetchRequestsCorrectly() { let whereClause = Where("key", isEqualTo: "value") - let request = CoreStoreFetchRequest() + let request = Internals.CoreStoreFetchRequest() whereClause.applyToFetchRequest(request) XCTAssertNotNil(request.predicate) - XCTAssertEqual(request.predicate, whereClause.predicate) + XCTAssertAllEqual(request.predicate, whereClause.predicate) } } diff --git a/Sources/AsynchronousDataTransaction.swift b/Sources/AsynchronousDataTransaction.swift index 3767b8e..fd89666 100644 --- a/Sources/AsynchronousDataTransaction.swift +++ b/Sources/AsynchronousDataTransaction.swift @@ -68,9 +68,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { */ public override func create(_ into: Into) -> D { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to create an entity of type \(cs_typeName(into.entityClass)) from an already committed \(cs_typeName(self))." + "Attempted to create an entity of type \(Internals.typeName(into.entityClass)) from an already committed \(Internals.typeName(self))." ) return super.create(into) @@ -84,9 +84,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { */ public override func edit(_ object: D?) -> D? { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to update an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))." + "Attempted to update an entity of type \(Internals.typeName(object)) from an already committed \(Internals.typeName(self))." ) return super.edit(object) @@ -101,9 +101,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { */ public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> D? { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to update an entity of type \(cs_typeName(into.entityClass)) from an already committed \(cs_typeName(self))." + "Attempted to update an entity of type \(Internals.typeName(into.entityClass)) from an already committed \(Internals.typeName(self))." ) return super.edit(into, objectID) @@ -116,9 +116,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { */ public override func delete(_ object: D?) { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to delete an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))." + "Attempted to delete an entity of type \(Internals.typeName(object)) from an already committed \(Internals.typeName(self))." ) super.delete(object) @@ -133,9 +133,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { */ public override func delete(_ object1: D?, _ object2: D?, _ objects: D?...) { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to delete an entities from an already committed \(cs_typeName(self))." + "Attempted to delete an entities from an already committed \(Internals.typeName(self))." ) super.delete(([object1, object2] + objects).compactMap { $0 }) @@ -148,9 +148,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { */ public override func delete(_ objects: S) where S.Iterator.Element: DynamicObject { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to delete an entities from an already committed \(cs_typeName(self))." + "Attempted to delete an entities from an already committed \(Internals.typeName(self))." ) super.delete(objects) diff --git a/Sources/BaseDataTransaction+Importing.swift b/Sources/BaseDataTransaction+Importing.swift index 37b8655..7c960c6 100644 --- a/Sources/BaseDataTransaction+Importing.swift +++ b/Sources/BaseDataTransaction+Importing.swift @@ -43,9 +43,9 @@ extension BaseDataTransaction { _ into: Into, source: D.ImportSource) throws -> D? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue." + "Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue." ) return try autoreleasepool { @@ -73,14 +73,14 @@ extension BaseDataTransaction { _ object: D, source: D.ImportSource) throws { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(cs_typeName(object)) outside the transaction's designated queue." + "Attempted to import an object of type \(Internals.typeName(object)) outside the transaction's designated queue." ) try autoreleasepool { - let entityType = cs_dynamicType(of: object) + let entityType = Internals.dynamicObjectType(of: object) guard entityType.shouldInsert(from: source, in: self) else { return @@ -101,9 +101,9 @@ extension BaseDataTransaction { _ into: Into, sourceArray: S) throws -> [D] where S.Iterator.Element == D.ImportSource { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue." + "Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue." ) return try autoreleasepool { @@ -137,9 +137,9 @@ extension BaseDataTransaction { _ into: Into, source: D.ImportSource) throws -> D? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue." + "Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue." ) return try autoreleasepool { @@ -190,9 +190,9 @@ extension BaseDataTransaction { sourceArray: S, preProcess: @escaping (_ mapping: [D.UniqueIDType: D.ImportSource]) throws -> [D.UniqueIDType: D.ImportSource] = { $0 }) throws -> [D] where S.Iterator.Element == D.ImportSource { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue." + "Attempted to import an object of type \(Internals.typeName(into.entityClass)) outside the transaction's designated queue." ) return try autoreleasepool { diff --git a/Sources/BaseDataTransaction+Querying.swift b/Sources/BaseDataTransaction+Querying.swift index d659fc2..7485e76 100644 --- a/Sources/BaseDataTransaction+Querying.swift +++ b/Sources/BaseDataTransaction+Querying.swift @@ -41,9 +41,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { @discardableResult public func deleteAll(_ from: From, _ deleteClauses: DeleteClause...) throws -> Int { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." + "Attempted to delete from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.deleteAll(from, deleteClauses) } @@ -58,9 +58,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { @discardableResult public func deleteAll(_ from: From, _ deleteClauses: [DeleteClause]) throws -> Int { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." + "Attempted to delete from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.deleteAll(from, deleteClauses) } @@ -76,9 +76,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { @discardableResult public func deleteAll(_ clauseChain: B) throws -> Int { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." + "Attempted to delete from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.deleteAll(clauseChain.from, clauseChain.fetchClauses) @@ -141,9 +141,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchOne(from, fetchClauses) } @@ -158,9 +158,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchOne(from, fetchClauses) } @@ -180,9 +180,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchOne(clauseChain) } @@ -197,9 +197,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchAll(from, fetchClauses) } @@ -214,9 +214,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchAll(from, fetchClauses) } @@ -236,9 +236,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchAll(clauseChain) } @@ -253,9 +253,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) throws -> Int { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchCount(from, fetchClauses) } @@ -270,9 +270,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchCount(from, fetchClauses) } @@ -292,9 +292,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchCount(_ clauseChain: B) throws -> Int { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchCount(clauseChain) } @@ -309,9 +309,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchObjectID(from, fetchClauses) } @@ -326,9 +326,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchObjectID(from, fetchClauses) } @@ -348,9 +348,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchObjectID(clauseChain) } @@ -365,9 +365,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchObjectIDs(from, fetchClauses) } @@ -382,9 +382,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchObjectIDs(from, fetchClauses) } @@ -404,9 +404,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.fetchObjectIDs(clauseChain) } @@ -427,9 +427,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> U? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(cs_typeName(self)) outside its designated queue." + "Attempted to query from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.queryValue(from, selectClause, queryClauses) } @@ -447,9 +447,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> U? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(cs_typeName(self)) outside its designated queue." + "Attempted to query from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.queryValue(from, selectClause, queryClauses) } @@ -471,9 +471,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(cs_typeName(self)) outside its designated queue." + "Attempted to query from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } @@ -491,9 +491,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> [[String: Any]] { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(cs_typeName(self)) outside its designated queue." + "Attempted to query from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.queryAttributes(from, selectClause, queryClauses) } @@ -511,9 +511,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> [[String: Any]] { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(cs_typeName(self)) outside its designated queue." + "Attempted to query from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.queryAttributes(from, selectClause, queryClauses) } @@ -544,9 +544,9 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { */ public func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(cs_typeName(self)) outside its designated queue." + "Attempted to query from a \(Internals.typeName(self)) outside its designated queue." ) return try self.context.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } diff --git a/Sources/BaseDataTransaction.swift b/Sources/BaseDataTransaction.swift index 64c1790..501617a 100644 --- a/Sources/BaseDataTransaction.swift +++ b/Sources/BaseDataTransaction.swift @@ -53,14 +53,14 @@ public /*abstract*/ class BaseDataTransaction { public func create(_ into: Into) -> D { let entityClass = into.entityClass - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to create an entity of type \(cs_typeName(entityClass)) outside its designated queue." + "Attempted to create an entity of type \(Internals.typeName(entityClass)) outside its designated queue." ) let context = self.context let dataStack = context.parentStack! - let entityIdentifier = EntityIdentifier(entityClass) + let entityIdentifier = Internals.EntityIdentifier(entityClass) if into.inferStoreIfPossible { switch dataStack.persistentStore( @@ -77,10 +77,10 @@ public /*abstract*/ class BaseDataTransaction { ) case (nil, true): - CoreStore.abort("Attempted to create an entity of type \(cs_typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.") + Internals.abort("Attempted to create an entity of type \(Internals.typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.") default: - CoreStore.abort("Attempted to create an entity of type \(cs_typeName(entityClass)), but a destination persistent store containing the entity type could not be found.") + Internals.abort("Attempted to create an entity of type \(Internals.typeName(entityClass)), but a destination persistent store containing the entity type could not be found.") } } else { @@ -100,16 +100,16 @@ public /*abstract*/ class BaseDataTransaction { ) case (nil, true): - CoreStore.abort("Attempted to create an entity of type \(cs_typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.") + Internals.abort("Attempted to create an entity of type \(Internals.typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.") default: if let configuration = into.configuration { - CoreStore.abort("Attempted to create an entity of type \(cs_typeName(entityClass)) into the configuration \"\(configuration)\", which it doesn't belong to.") + Internals.abort("Attempted to create an entity of type \(Internals.typeName(entityClass)) into the configuration \"\(configuration)\", which it doesn't belong to.") } else { - CoreStore.abort("Attempted to create an entity of type \(cs_typeName(entityClass)) into the default configuration, which it doesn't belong to.") + Internals.abort("Attempted to create an entity of type \(Internals.typeName(entityClass)) into the default configuration, which it doesn't belong to.") } } } @@ -123,9 +123,9 @@ public /*abstract*/ class BaseDataTransaction { */ public func edit(_ object: D?) -> D? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to update an entity of type \(cs_typeName(object)) outside its designated queue." + "Attempted to update an entity of type \(Internals.typeName(object)) outside its designated queue." ) guard let object = object else { @@ -143,14 +143,14 @@ public /*abstract*/ class BaseDataTransaction { */ public func edit(_ into: Into, _ objectID: NSManagedObjectID) -> D? { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to update an entity of type \(cs_typeName(into.entityClass)) outside its designated queue." + "Attempted to update an entity of type \(Internals.typeName(into.entityClass)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( into.inferStoreIfPossible || (into.configuration ?? DataStack.defaultConfigurationName) == objectID.persistentStore?.configurationName, - "Attempted to update an entity of type \(cs_typeName(into.entityClass)) but the specified persistent store do not match the `NSManagedObjectID`." + "Attempted to update an entity of type \(Internals.typeName(into.entityClass)) but the specified persistent store do not match the `NSManagedObjectID`." ) return self.fetchExisting(objectID) } @@ -162,7 +162,7 @@ public /*abstract*/ class BaseDataTransaction { */ public func delete(_ object: D?) { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), "Attempted to delete an entity outside its designated queue." ) @@ -191,7 +191,7 @@ public /*abstract*/ class BaseDataTransaction { */ public func delete(_ objects: S) where S.Iterator.Element: DynamicObject { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), "Attempted to delete entities outside their designated queue." ) @@ -204,7 +204,7 @@ public /*abstract*/ class BaseDataTransaction { */ public func refreshAndMergeAllObjects() { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), "Attempted to refresh entities outside their designated queue." ) @@ -222,13 +222,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func objectHasPersistentChangedValues(_ entity: D) -> Bool { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access inserted objects from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access inserted objects from an already committed \(cs_typeName(self))." + "Attempted to access inserted objects from an already committed \(Internals.typeName(self))." ) return entity.cs_toRaw().hasPersistentChangedValues } @@ -241,13 +241,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func insertedObjects(_ entity: D.Type) -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access inserted objects from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access inserted objects from an already committed \(cs_typeName(self))." + "Attempted to access inserted objects from an already committed \(Internals.typeName(self))." ) return Set(self.context.insertedObjects.compactMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) } @@ -259,13 +259,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func insertedObjectIDs() -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access inserted object IDs from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access inserted object IDs from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))." + "Attempted to access inserted objects IDs from an already committed \(Internals.typeName(self))." ) return Set(self.context.insertedObjects.map { $0.objectID }) } @@ -278,13 +278,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func insertedObjectIDs(_ entity: D.Type) -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access inserted object IDs from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access inserted object IDs from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))." + "Attempted to access inserted objects IDs from an already committed \(Internals.typeName(self))." ) return Set(self.context.insertedObjects.compactMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) } @@ -297,13 +297,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func updatedObjects(_ entity: D.Type) -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access updated objects from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access updated objects from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access updated objects from an already committed \(cs_typeName(self))." + "Attempted to access updated objects from an already committed \(Internals.typeName(self))." ) return Set(self.context.updatedObjects.compactMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) } @@ -315,13 +315,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func updatedObjectIDs() -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access updated object IDs from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access updated object IDs from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access updated object IDs from an already committed \(cs_typeName(self))." + "Attempted to access updated object IDs from an already committed \(Internals.typeName(self))." ) return Set(self.context.updatedObjects.map { $0.objectID }) } @@ -334,13 +334,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func updatedObjectIDs(_ entity: D.Type) -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access updated object IDs from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access updated object IDs from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access updated object IDs from an already committed \(cs_typeName(self))." + "Attempted to access updated object IDs from an already committed \(Internals.typeName(self))." ) return Set(self.context.updatedObjects.compactMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) } @@ -353,13 +353,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func deletedObjects(_ entity: D.Type) -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access deleted objects from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access deleted objects from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access deleted objects from an already committed \(cs_typeName(self))." + "Attempted to access deleted objects from an already committed \(Internals.typeName(self))." ) return Set(self.context.deletedObjects.compactMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) } @@ -372,13 +372,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func deletedObjectIDs() -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access deleted object IDs from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access deleted object IDs from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access deleted object IDs from an already committed \(cs_typeName(self))." + "Attempted to access deleted object IDs from an already committed \(Internals.typeName(self))." ) return Set(self.context.deletedObjects.map { $0.objectID }) } @@ -391,13 +391,13 @@ public /*abstract*/ class BaseDataTransaction { */ public func deletedObjectIDs(_ entity: D.Type) -> Set { - CoreStore.assert( + Internals.assert( self.isRunningInAllowedQueue(), - "Attempted to access deleted object IDs from a \(cs_typeName(self)) outside its designated queue." + "Attempted to access deleted object IDs from a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to access deleted object IDs from an already committed \(cs_typeName(self))." + "Attempted to access deleted object IDs from an already committed \(Internals.typeName(self))." ) return Set(self.context.deletedObjects.compactMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) } diff --git a/Sources/CSAsynchronousDataTransaction.swift b/Sources/CSAsynchronousDataTransaction.swift index 80ad0fc..55be08a 100644 --- a/Sources/CSAsynchronousDataTransaction.swift +++ b/Sources/CSAsynchronousDataTransaction.swift @@ -46,13 +46,13 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction, CoreSto @objc public func commitWithSuccess(_ success: (() -> Void)?, failure: ((CSError) -> Void)?) { - CoreStore.assert( + Internals.assert( self.bridgeToSwift.transactionQueue.cs_isCurrentExecutionContext(), - "Attempted to commit a \(cs_typeName(self)) outside its designated queue." + "Attempted to commit a \(Internals.typeName(self)) outside its designated queue." ) - CoreStore.assert( + Internals.assert( !self.bridgeToSwift.isCommitted, - "Attempted to commit a \(cs_typeName(self)) more than once." + "Attempted to commit a \(Internals.typeName(self)) more than once." ) self.bridgeToSwift.autoCommit { (_, error) in diff --git a/Sources/CSBaseDataTransaction+Querying.swift b/Sources/CSBaseDataTransaction+Querying.swift index 5092d16..d993df4 100644 --- a/Sources/CSBaseDataTransaction+Querying.swift +++ b/Sources/CSBaseDataTransaction+Querying.swift @@ -89,9 +89,9 @@ extension CSBaseDataTransaction { @objc public func fetchOneFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> Any? { - CoreStore.assert( + Internals.assert( self.swiftTransaction.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return (try? self.swiftTransaction.context.fetchOne(from, fetchClauses))? .flatMap({ $0 }) @@ -107,9 +107,9 @@ extension CSBaseDataTransaction { @objc public func fetchAllFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> [Any]? { - CoreStore.assert( + Internals.assert( self.swiftTransaction.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return (try? self.swiftTransaction.context.fetchAll(from, fetchClauses)) .flatMap({ $0 }) @@ -125,9 +125,9 @@ extension CSBaseDataTransaction { @objc public func fetchCountFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> NSNumber? { - CoreStore.assert( + Internals.assert( self.swiftTransaction.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return (try? self.swiftTransaction.context.fetchCount(from, fetchClauses)) .flatMap({ NSNumber(value: $0) }) @@ -143,9 +143,9 @@ extension CSBaseDataTransaction { @objc public func fetchObjectIDFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> NSManagedObjectID? { - CoreStore.assert( + Internals.assert( self.swiftTransaction.isRunningInAllowedQueue(), - "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." + "Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue." ) return (try? self.swiftTransaction.context.fetchObjectID(from, fetchClauses)) .flatMap({ $0 }) @@ -164,9 +164,9 @@ extension CSBaseDataTransaction { @objc public func queryValueFrom(_ from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> Any? { - CoreStore.assert( + Internals.assert( self.swiftTransaction.isRunningInAllowedQueue(), - "Attempted to query from a \(cs_typeName(self)) outside its designated queue." + "Attempted to query from a \(Internals.typeName(self)) outside its designated queue." ) return (try? self.swiftTransaction.context.queryValue(from, selectClause, queryClauses)) .flatMap({ $0 }) @@ -185,9 +185,9 @@ extension CSBaseDataTransaction { @objc public func queryAttributesFrom(_ from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> [[String: Any]]? { - CoreStore.assert( + Internals.assert( self.swiftTransaction.isRunningInAllowedQueue(), - "Attempted to query from a \(cs_typeName(self)) outside its designated queue." + "Attempted to query from a \(Internals.typeName(self)) outside its designated queue." ) return (try? self.swiftTransaction.context.queryAttributes(from, selectClause, queryClauses)) .flatMap({ $0 }) diff --git a/Sources/CSCoreStore+Migrating.swift b/Sources/CSCoreStore+Migrating.swift index 674a284..2c75467 100644 --- a/Sources/CSCoreStore+Migrating.swift +++ b/Sources/CSCoreStore+Migrating.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CSCoreStore +@available(*, deprecated, message: "Call methods directly from the CSDataStack instead") extension CSCoreStore { /** diff --git a/Sources/CSCoreStore+Observing.swift b/Sources/CSCoreStore+Observing.swift index e56b675..c4e5b79 100644 --- a/Sources/CSCoreStore+Observing.swift +++ b/Sources/CSCoreStore+Observing.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CSCoreStore +@available(*, deprecated, message: "Call methods directly from the CSDataStack instead") @available(macOS 10.12, *) extension CSCoreStore { diff --git a/Sources/CSCoreStore+Querying.swift b/Sources/CSCoreStore+Querying.swift index a4537e8..d241222 100644 --- a/Sources/CSCoreStore+Querying.swift +++ b/Sources/CSCoreStore+Querying.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CSCoreStore +@available(*, deprecated, message: "Call methods directly from the DataStack instead") extension CSCoreStore { /** diff --git a/Sources/CSCoreStore+Setup.swift b/Sources/CSCoreStore+Setup.swift index 667d325..0028a94 100644 --- a/Sources/CSCoreStore+Setup.swift +++ b/Sources/CSCoreStore+Setup.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CSCoreStore +@available(*, deprecated, message: "Call methods directly from the CSDataStack instead") extension CSCoreStore { /** diff --git a/Sources/CSCoreStore+Transaction.swift b/Sources/CSCoreStore+Transaction.swift index 67b9e07..bda8282 100644 --- a/Sources/CSCoreStore+Transaction.swift +++ b/Sources/CSCoreStore+Transaction.swift @@ -28,6 +28,7 @@ import Foundation // MARK: - CSCoreStore +@available(*, deprecated, message: "Call methods directly from the CSDataStack instead") extension CSCoreStore { /** diff --git a/Sources/CSCoreStore.swift b/Sources/CSCoreStore.swift index 7dbb47f..ef5709b 100644 --- a/Sources/CSCoreStore.swift +++ b/Sources/CSCoreStore.swift @@ -33,6 +33,7 @@ import Foundation - SeeAlso: `CoreStore` */ +@available(*, deprecated, message: "Call methods directly from the CSDataStack instead") @objc public final class CSCoreStore: NSObject { @@ -45,14 +46,8 @@ public final class CSCoreStore: NSObject { @objc public static var defaultStack: CSDataStack { - get { - - return CoreStore.defaultStack.bridgeToObjectiveC - } - set { - - CoreStore.defaultStack = newValue.bridgeToSwift - } + get { return Shared.defaultStack.bridgeToObjectiveC } + set { Shared.defaultStack = newValue.bridgeToSwift } } diff --git a/Sources/CSDataStack+Observing.swift b/Sources/CSDataStack+Observing.swift index 5cc88f3..f7f9c4a 100644 --- a/Sources/CSDataStack+Observing.swift +++ b/Sources/CSDataStack+Observing.swift @@ -54,11 +54,11 @@ extension CSDataStack { @objc public func monitorListFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> CSListMonitor { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) - CoreStore.assert( + Internals.assert( fetchClauses.contains { $0 is CSOrderBy }, "A CSListMonitor requires a CSOrderBy clause." ) @@ -83,11 +83,11 @@ extension CSDataStack { @objc public func monitorListByCreatingAsynchronously(_ createAsynchronously: @escaping (CSListMonitor) -> Void, from: CSFrom, fetchClauses: [CSFetchClause]) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) - CoreStore.assert( + Internals.assert( fetchClauses.contains { $0 is CSOrderBy }, "A CSListMonitor requires an CSOrderBy clause." ) @@ -117,11 +117,11 @@ extension CSDataStack { @objc public func monitorSectionedListFrom(_ from: CSFrom, sectionBy: CSSectionBy, fetchClauses: [CSFetchClause]) -> CSListMonitor { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) - CoreStore.assert( + Internals.assert( fetchClauses.contains { $0 is CSOrderBy }, "A CSListMonitor requires an CSOrderBy clause." ) @@ -146,11 +146,11 @@ extension CSDataStack { */ public func monitorSectionedListByCreatingAsynchronously(_ createAsynchronously: @escaping (CSListMonitor) -> Void, from: CSFrom, sectionBy: CSSectionBy, fetchClauses: [CSFetchClause]) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) - CoreStore.assert( + Internals.assert( fetchClauses.contains { $0 is CSOrderBy }, "A CSListMonitor requires an CSOrderBy clause." ) diff --git a/Sources/CSDataStack+Querying.swift b/Sources/CSDataStack+Querying.swift index b653ee5..29ef10a 100644 --- a/Sources/CSDataStack+Querying.swift +++ b/Sources/CSDataStack+Querying.swift @@ -89,9 +89,9 @@ extension CSDataStack { @objc public func fetchOneFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> Any? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return (try? self.bridgeToSwift.mainContext.fetchOne(from, fetchClauses))? .flatMap({ $0 }) @@ -107,9 +107,9 @@ extension CSDataStack { @objc public func fetchAllFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> [Any]? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return (try? self.bridgeToSwift.mainContext.fetchAll(from, fetchClauses)) .flatMap({ $0 }) @@ -125,9 +125,9 @@ extension CSDataStack { @objc public func fetchCountFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> NSNumber? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return (try? self.bridgeToSwift.mainContext.fetchCount(from, fetchClauses)) .flatMap({ NSNumber(value: $0) }) @@ -143,9 +143,9 @@ extension CSDataStack { @objc public func fetchObjectIDFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> NSManagedObjectID? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return (try? self.bridgeToSwift.mainContext.fetchObjectID(from, fetchClauses))? .flatMap({ $0 }) @@ -161,9 +161,9 @@ extension CSDataStack { @objc public func fetchObjectIDsFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> [NSManagedObjectID]? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return (try? self.bridgeToSwift.mainContext.fetchObjectIDs(from, fetchClauses)) .flatMap({ $0 }) @@ -182,9 +182,9 @@ extension CSDataStack { @objc public func queryValueFrom(_ from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> Any? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to query from a \(cs_typeName(self)) outside the main thread." + "Attempted to query from a \(Internals.typeName(self)) outside the main thread." ) return (try? self.bridgeToSwift.mainContext.queryValue(from, selectClause, queryClauses)) .flatMap({ $0 }) @@ -203,9 +203,9 @@ extension CSDataStack { @objc public func queryAttributesFrom(_ from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> [[String: Any]]? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to query from a \(cs_typeName(self)) outside the main thread." + "Attempted to query from a \(Internals.typeName(self)) outside the main thread." ) return (try? self.bridgeToSwift.mainContext.queryAttributes(from, selectClause, queryClauses)) .flatMap({ $0 }) diff --git a/Sources/CSDataStack+Transaction.swift b/Sources/CSDataStack+Transaction.swift index 72e9839..1965705 100644 --- a/Sources/CSDataStack+Transaction.swift +++ b/Sources/CSDataStack+Transaction.swift @@ -45,9 +45,9 @@ extension CSDataStack { closure(csTransaction) if !transaction.isCommitted && transaction.hasChanges { - CoreStore.log( + Internals.log( .warning, - message: "The closure for the \(cs_typeName(csTransaction)) completed without being committed. All changes made within the transaction were discarded." + message: "The closure for the \(Internals.typeName(csTransaction)) completed without being committed. All changes made within the transaction were discarded." ) } try transaction.cancel() @@ -77,9 +77,9 @@ extension CSDataStack { closure(csTransaction) if !transaction.isCommitted && transaction.hasChanges { - CoreStore.log( + Internals.log( .warning, - message: "The closure for the \(cs_typeName(csTransaction)) completed without being committed. All changes made within the transaction were discarded." + message: "The closure for the \(Internals.typeName(csTransaction)) completed without being committed. All changes made within the transaction were discarded." ) } try transaction.cancel() diff --git a/Sources/CSFrom.swift b/Sources/CSFrom.swift index 155b6cb..fd02314 100644 --- a/Sources/CSFrom.swift +++ b/Sources/CSFrom.swift @@ -97,7 +97,7 @@ public final class CSFrom: NSObject { self.init(From(entityClass, nil)) default: - CoreStore.abort("The configuration argument only accepts NSString and NSNull values") + Internals.abort("The configuration argument only accepts NSString and NSNull values") } } @@ -126,7 +126,7 @@ public final class CSFrom: NSObject { arguments.append(nil) default: - CoreStore.abort("The configurations argument only accepts NSString and NSNull values") + Internals.abort("The configurations argument only accepts NSString and NSNull values") } } self.init(From(entityClass, arguments)) diff --git a/Sources/CSSelect.swift b/Sources/CSSelect.swift index 2a8c105..9c737f9 100644 --- a/Sources/CSSelect.swift +++ b/Sources/CSSelect.swift @@ -467,9 +467,9 @@ public final class CSSelect: NSObject { } else { - CoreStore.log( + Internals.log( .warning, - message: "The key path \"\(keyPath)\" could not be resolved in entity \(cs_typeName(entityDescription.managedObjectClassName)) as an attribute and will be ignored by \(cs_typeName(self)) query clause." + message: "The key path \"\(keyPath)\" could not be resolved in entity \(Internals.typeName(entityDescription.managedObjectClassName)) as an attribute and will be ignored by \(Internals.typeName(self)) query clause." ) } diff --git a/Sources/CoreStore+Logging.swift b/Sources/CoreStore+Logging.swift index 9eb48e9..b2fe6ed 100644 --- a/Sources/CoreStore+Logging.swift +++ b/Sources/CoreStore+Logging.swift @@ -26,22 +26,16 @@ import Foundation -// MARK: - CoreStore +// MARK: - Internal + +extension Internals { -extension CoreStore { - - /** - The `CoreStoreLogger` instance to be used. The default logger is an instance of a `DefaultLogger`. - */ - public static var logger: CoreStoreLogger = DefaultLogger() - - // MARK: Internal - + @inline(__always) internal static func log(_ level: LogLevel, message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) { - - self.logger.log( + + Shared.logger.log( level: level, message: message, fileName: fileName, @@ -49,11 +43,11 @@ extension CoreStore { functionName: functionName ) } - + @inline(__always) internal static func log(_ error: CoreStoreError, _ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) { - - self.logger.log( + + Shared.logger.log( error: error, message: message, fileName: fileName, @@ -61,11 +55,11 @@ extension CoreStore { functionName: functionName ) } - + @inline(__always) internal static func assert( _ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) { - - self.logger.assert( + + Shared.logger.assert( condition(), message: message(), fileName: fileName, @@ -73,11 +67,11 @@ extension CoreStore { functionName: functionName ) } - + @inline(__always) internal static func abort(_ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) -> Never { - - self.logger.abort( + + Shared.logger.abort( message, fileName: fileName, lineNumber: lineNumber, diff --git a/Sources/CoreStore+Migration.swift b/Sources/CoreStore+Migration.swift index 046ea2f..0615d7c 100644 --- a/Sources/CoreStore+Migration.swift +++ b/Sources/CoreStore+Migration.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CoreStore +@available(*, deprecated, message: "Call methods directly from the DataStack instead") extension CoreStore { /** @@ -49,7 +50,7 @@ extension CoreStore { */ public static func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) { - self.defaultStack.addStorage(storage, completion: completion) + Shared.defaultStack.addStorage(storage, completion: completion) } /** @@ -71,7 +72,7 @@ extension CoreStore { */ public static func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) -> Progress? { - return self.defaultStack.addStorage(storage, completion: completion) + return Shared.defaultStack.addStorage(storage, completion: completion) } /** @@ -103,7 +104,7 @@ extension CoreStore { */ public static func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) { - self.defaultStack.addStorage(storage, completion: completion) + Shared.defaultStack.addStorage(storage, completion: completion) } /** @@ -116,7 +117,7 @@ extension CoreStore { */ public static func upgradeStorageIfNeeded(_ storage: T, completion: @escaping (MigrationResult) -> Void) throws -> Progress? { - return try self.defaultStack.upgradeStorageIfNeeded(storage, completion: completion) + return try Shared.defaultStack.upgradeStorageIfNeeded(storage, completion: completion) } /** @@ -128,6 +129,6 @@ extension CoreStore { */ public static func requiredMigrationsForStorage(_ storage: T) throws -> [MigrationType] { - return try self.defaultStack.requiredMigrationsForStorage(storage) + return try Shared.defaultStack.requiredMigrationsForStorage(storage) } } diff --git a/Sources/CoreStore+Observing.swift b/Sources/CoreStore+Observing.swift index 431c98f..9b44ead 100644 --- a/Sources/CoreStore+Observing.swift +++ b/Sources/CoreStore+Observing.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CoreStore +@available(*, deprecated, message: "Call methods directly from the DataStack instead") @available(macOS 10.12, *) extension CoreStore { @@ -40,7 +41,7 @@ extension CoreStore { */ public static func monitorObject(_ object: D) -> ObjectMonitor { - return self.defaultStack.monitorObject(object) + return Shared.defaultStack.monitorObject(object) } /** @@ -52,7 +53,7 @@ extension CoreStore { */ public static func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { - return self.defaultStack.monitorList(from, fetchClauses) + return Shared.defaultStack.monitorList(from, fetchClauses) } /** @@ -64,7 +65,7 @@ extension CoreStore { */ public static func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { - return self.defaultStack.monitorList(from, fetchClauses) + return Shared.defaultStack.monitorList(from, fetchClauses) } /** @@ -81,7 +82,7 @@ extension CoreStore { */ public static func monitorList(_ clauseChain: B) -> ListMonitor { - return self.defaultStack.monitorList(clauseChain.from, clauseChain.fetchClauses) + return Shared.defaultStack.monitorList(clauseChain.from, clauseChain.fetchClauses) } /** @@ -93,7 +94,7 @@ extension CoreStore { */ public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { - self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) + Shared.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } /** @@ -105,7 +106,7 @@ extension CoreStore { */ public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { - self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) + Shared.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } /** @@ -126,7 +127,7 @@ extension CoreStore { */ public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { - self.defaultStack.monitorList( + Shared.defaultStack.monitorList( createAsynchronously: createAsynchronously, clauseChain.from, clauseChain.fetchClauses @@ -143,7 +144,7 @@ extension CoreStore { */ public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { - return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) + return Shared.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) } /** @@ -156,7 +157,7 @@ extension CoreStore { */ public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { - return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) + return Shared.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) } /** @@ -174,7 +175,7 @@ extension CoreStore { */ public static func monitorSectionedList(_ clauseChain: B) -> ListMonitor { - return self.defaultStack.monitorSectionedList( + return Shared.defaultStack.monitorSectionedList( clauseChain.from, clauseChain.sectionBy, clauseChain.fetchClauses @@ -191,7 +192,7 @@ extension CoreStore { */ public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { - self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) + Shared.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } /** @@ -204,7 +205,7 @@ extension CoreStore { */ public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { - self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) + Shared.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } /** @@ -225,7 +226,7 @@ extension CoreStore { */ public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { - self.defaultStack.monitorSectionedList( + Shared.defaultStack.monitorSectionedList( createAsynchronously: createAsynchronously, clauseChain.from, clauseChain.sectionBy, diff --git a/Sources/CoreStore+Querying.swift b/Sources/CoreStore+Querying.swift index 90b928c..aa33d1d 100644 --- a/Sources/CoreStore+Querying.swift +++ b/Sources/CoreStore+Querying.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CoreStore +@available(*, deprecated, message: "Call methods directly from the DataStack instead") extension CoreStore { /** @@ -39,7 +40,7 @@ extension CoreStore { */ public static func fetchExisting(_ object: D) -> D? { - return self.defaultStack.fetchExisting(object) + return Shared.defaultStack.fetchExisting(object) } /** @@ -50,7 +51,7 @@ extension CoreStore { */ public static func fetchExisting(_ objectID: NSManagedObjectID) -> D? { - return self.defaultStack.fetchExisting(objectID) + return Shared.defaultStack.fetchExisting(objectID) } /** @@ -61,7 +62,7 @@ extension CoreStore { */ public static func fetchExisting(_ objects: S) -> [D] where S.Iterator.Element == D { - return self.defaultStack.fetchExisting(objects) + return Shared.defaultStack.fetchExisting(objects) } /** @@ -72,7 +73,7 @@ extension CoreStore { */ public static func fetchExisting(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID { - return self.defaultStack.fetchExisting(objectIDs) + return Shared.defaultStack.fetchExisting(objectIDs) } /** @@ -85,7 +86,7 @@ extension CoreStore { */ public static func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { - return try self.defaultStack.fetchOne(from, fetchClauses) + return try Shared.defaultStack.fetchOne(from, fetchClauses) } /** @@ -98,7 +99,7 @@ extension CoreStore { */ public static func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { - return try self.defaultStack.fetchOne(from, fetchClauses) + return try Shared.defaultStack.fetchOne(from, fetchClauses) } /** @@ -116,7 +117,7 @@ extension CoreStore { */ public static func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { - return try self.defaultStack.fetchOne(clauseChain) + return try Shared.defaultStack.fetchOne(clauseChain) } /** @@ -129,7 +130,7 @@ extension CoreStore { */ public static func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { - return try self.defaultStack.fetchAll(from, fetchClauses) + return try Shared.defaultStack.fetchAll(from, fetchClauses) } /** @@ -142,7 +143,7 @@ extension CoreStore { */ public static func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { - return try self.defaultStack.fetchAll(from, fetchClauses) + return try Shared.defaultStack.fetchAll(from, fetchClauses) } /** @@ -160,7 +161,7 @@ extension CoreStore { */ public static func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { - return try self.defaultStack.fetchAll(clauseChain) + return try Shared.defaultStack.fetchAll(clauseChain) } /** @@ -173,7 +174,7 @@ extension CoreStore { */ public static func fetchCount(_ from: From, _ fetchClauses: FetchClause...) throws -> Int { - return try self.defaultStack.fetchCount(from, fetchClauses) + return try Shared.defaultStack.fetchCount(from, fetchClauses) } /** @@ -186,7 +187,7 @@ extension CoreStore { */ public static func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int { - return try self.defaultStack.fetchCount(from, fetchClauses) + return try Shared.defaultStack.fetchCount(from, fetchClauses) } /** @@ -204,7 +205,7 @@ extension CoreStore { */ public static func fetchCount(_ clauseChain: B) throws -> Int { - return try self.defaultStack.fetchCount(clauseChain) + return try Shared.defaultStack.fetchCount(clauseChain) } /** @@ -217,7 +218,7 @@ extension CoreStore { */ public static func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? { - return try self.defaultStack.fetchObjectID(from, fetchClauses) + return try Shared.defaultStack.fetchObjectID(from, fetchClauses) } /** @@ -230,7 +231,7 @@ extension CoreStore { */ public static func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? { - return try self.defaultStack.fetchObjectID(from, fetchClauses) + return try Shared.defaultStack.fetchObjectID(from, fetchClauses) } /** @@ -248,7 +249,7 @@ extension CoreStore { */ public static func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { - return try self.defaultStack.fetchObjectID(clauseChain) + return try Shared.defaultStack.fetchObjectID(clauseChain) } /** @@ -261,7 +262,7 @@ extension CoreStore { */ public static func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] { - return try self.defaultStack.fetchObjectIDs(from, fetchClauses) + return try Shared.defaultStack.fetchObjectIDs(from, fetchClauses) } /** @@ -274,7 +275,7 @@ extension CoreStore { */ public static func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] { - return try self.defaultStack.fetchObjectIDs(from, fetchClauses) + return try Shared.defaultStack.fetchObjectIDs(from, fetchClauses) } /** @@ -292,7 +293,7 @@ extension CoreStore { */ public static func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { - return try self.defaultStack.fetchObjectIDs(clauseChain) + return try Shared.defaultStack.fetchObjectIDs(clauseChain) } /** @@ -308,7 +309,7 @@ extension CoreStore { */ public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> U? { - return try self.defaultStack.queryValue(from, selectClause, queryClauses) + return try Shared.defaultStack.queryValue(from, selectClause, queryClauses) } /** @@ -324,7 +325,7 @@ extension CoreStore { */ public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> U? { - return try self.defaultStack.queryValue(from, selectClause, queryClauses) + return try Shared.defaultStack.queryValue(from, selectClause, queryClauses) } /** @@ -344,7 +345,7 @@ extension CoreStore { */ public static func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { - return try self.defaultStack.queryValue(clauseChain) + return try Shared.defaultStack.queryValue(clauseChain) } /** @@ -360,7 +361,7 @@ extension CoreStore { */ public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> [[String: Any]] { - return try self.defaultStack.queryAttributes(from, selectClause, queryClauses) + return try Shared.defaultStack.queryAttributes(from, selectClause, queryClauses) } /** @@ -376,7 +377,7 @@ extension CoreStore { */ public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> [[String: Any]] { - return try self.defaultStack.queryAttributes(from, selectClause, queryClauses) + return try Shared.defaultStack.queryAttributes(from, selectClause, queryClauses) } /** @@ -405,6 +406,6 @@ extension CoreStore { */ public static func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { - return try self.defaultStack.queryAttributes(clauseChain) + return try Shared.defaultStack.queryAttributes(clauseChain) } } diff --git a/Sources/CoreStore+Setup.swift b/Sources/CoreStore+Setup.swift index c3e3e41..af45f8b 100644 --- a/Sources/CoreStore+Setup.swift +++ b/Sources/CoreStore+Setup.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CoreStore +@available(*, deprecated, message: "Call methods directly from the DataStack instead") extension CoreStore { /** @@ -36,7 +37,7 @@ extension CoreStore { */ public static var modelVersion: String { - return self.defaultStack.modelVersion + return Shared.defaultStack.modelVersion } /** @@ -44,7 +45,7 @@ extension CoreStore { */ public static func entityTypesByName(for type: NSManagedObject.Type) -> [EntityName: NSManagedObject.Type] { - return self.defaultStack.entityTypesByName(for: type) + return Shared.defaultStack.entityTypesByName(for: type) } /** @@ -52,7 +53,7 @@ extension CoreStore { */ public static func entityTypesByName(for type: CoreStoreObject.Type) -> [EntityName: CoreStoreObject.Type] { - return self.defaultStack.entityTypesByName(for: type) + return Shared.defaultStack.entityTypesByName(for: type) } /** @@ -60,7 +61,7 @@ extension CoreStore { */ public static func entityDescription(for type: NSManagedObject.Type) -> NSEntityDescription? { - return self.defaultStack.entityDescription(for: type) + return Shared.defaultStack.entityDescription(for: type) } /** @@ -68,7 +69,7 @@ extension CoreStore { */ public static func entityDescription(for type: CoreStoreObject.Type) -> NSEntityDescription? { - return self.defaultStack.entityDescription(for: type) + return Shared.defaultStack.entityDescription(for: type) } /** @@ -81,7 +82,7 @@ extension CoreStore { @discardableResult public static func addStorageAndWait() throws -> SQLiteStore { - return try self.defaultStack.addStorageAndWait(SQLiteStore()) + return try Shared.defaultStack.addStorageAndWait(SQLiteStore()) } /** @@ -96,7 +97,7 @@ extension CoreStore { @discardableResult public static func addStorageAndWait(_ storage: T) throws -> T { - return try self.defaultStack.addStorageAndWait(storage) + return try Shared.defaultStack.addStorageAndWait(storage) } /** @@ -111,7 +112,7 @@ extension CoreStore { @discardableResult public static func addStorageAndWait(_ storage: T) throws -> T { - return try self.defaultStack.addStorageAndWait(storage) + return try Shared.defaultStack.addStorageAndWait(storage) } /** @@ -137,6 +138,6 @@ extension CoreStore { @discardableResult public static func addStorageAndWait(_ storage: T) throws -> T { - return try self.defaultStack.addStorageAndWait(storage) + return try Shared.defaultStack.addStorageAndWait(storage) } } diff --git a/Sources/CoreStore+Transaction.swift b/Sources/CoreStore+Transaction.swift index a784ec9..8381ce0 100644 --- a/Sources/CoreStore+Transaction.swift +++ b/Sources/CoreStore+Transaction.swift @@ -28,6 +28,7 @@ import Foundation // MARK: - CoreStore +@available(*, deprecated, message: "Call methods directly from the DataStack instead") extension CoreStore { /** @@ -38,7 +39,7 @@ extension CoreStore { */ public static func perform(asynchronous task: @escaping (_ transaction: AsynchronousDataTransaction) throws -> T, completion: @escaping (AsynchronousDataTransaction.Result) -> Void) { - self.defaultStack.perform(asynchronous: task, completion: completion) + Shared.defaultStack.perform(asynchronous: task, completion: completion) } /** @@ -50,7 +51,7 @@ extension CoreStore { */ public static func perform(asynchronous task: @escaping (_ transaction: AsynchronousDataTransaction) throws -> T, success: @escaping (T) -> Void, failure: @escaping (CoreStoreError) -> Void) { - self.defaultStack.perform(asynchronous: task, success: success, failure: failure) + Shared.defaultStack.perform(asynchronous: task, success: success, failure: failure) } /** @@ -63,7 +64,7 @@ extension CoreStore { */ public static func perform(synchronous task: ((_ transaction: SynchronousDataTransaction) throws -> T), waitForAllObservers: Bool = true) throws -> T { - return try self.defaultStack.perform(synchronous: task, waitForAllObservers: waitForAllObservers) + return try Shared.defaultStack.perform(synchronous: task, waitForAllObservers: waitForAllObservers) } /** @@ -74,7 +75,7 @@ extension CoreStore { */ public static func beginUnsafe(supportsUndo: Bool = false) -> UnsafeDataTransaction { - return self.defaultStack.beginUnsafe(supportsUndo: supportsUndo) + return Shared.defaultStack.beginUnsafe(supportsUndo: supportsUndo) } /** @@ -82,6 +83,6 @@ extension CoreStore { */ public static func refreshAndMergeAllObjects() { - self.defaultStack.refreshAndMergeAllObjects() + Shared.defaultStack.refreshAndMergeAllObjects() } } diff --git a/Sources/CoreStore.swift b/Sources/CoreStore.swift index a365dd1..d42ed7f 100644 --- a/Sources/CoreStore.swift +++ b/Sources/CoreStore.swift @@ -31,39 +31,20 @@ import CoreData /** `CoreStore` is the main entry point for all other APIs. */ +@available(*, deprecated, message: "Call methods directly from the DataStack instead") public enum CoreStore { - - /** - The default `DataStack` instance to be used. If `defaultStack` is not set before the first time accessed, a default-configured `DataStack` will be created. - - SeeAlso: `DataStack` - - Note: Changing the `defaultStack` is thread safe, but it is recommended to setup `DataStacks` on a common queue (e.g. the main queue). - */ + + @available(*, unavailable, renamed: "Shared.logger") + public static var logger: CoreStoreLogger { + + get { return Shared.logger } + set { Shared.logger = newValue } + } + + @available(*, unavailable, renamed: "Shared.defaultStack") public static var defaultStack: DataStack { - get { - - self.defaultStackBarrierQueue.sync(flags: .barrier) { - - if self.defaultStackInstance == nil { - - self.defaultStackInstance = DataStack() - } - } - return self.defaultStackInstance! - } - set { - - self.defaultStackBarrierQueue.async(flags: .barrier) { - - self.defaultStackInstance = newValue - } - } + get { return Shared.defaultStack } + set { Shared.defaultStack = newValue } } - - - // MARK: Private - - private static let defaultStackBarrierQueue = DispatchQueue.concurrent("com.coreStore.defaultStackBarrierQueue") - - private static var defaultStackInstance: DataStack? } diff --git a/Sources/CoreStoreFetchRequest.swift b/Sources/CoreStoreFetchRequest.swift deleted file mode 100644 index 668d7ad..0000000 --- a/Sources/CoreStoreFetchRequest.swift +++ /dev/null @@ -1,91 +0,0 @@ -// -// CoreStoreFetchRequest.swift -// CoreStore -// -// Copyright © 2019 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 -import ObjectiveC - - -// MARK: - CoreStoreFetchRequest - -// Bugfix for NSFetchRequest messing up memory management for `affectedStores` -// http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specified -internal final class CoreStoreFetchRequest: NSFetchRequest { - - @nonobjc - internal func safeAffectedStores() -> [NSPersistentStore]? { - - return self.copiedAffectedStores as! [NSPersistentStore]? - } - - @nonobjc @inline(__always) - internal func staticCast() -> NSFetchRequest { - - return unsafeBitCast(self, to: NSFetchRequest.self) - } - - @nonobjc @inline(__always) - internal func dynamicCast() -> NSFetchRequest { - - return unsafeBitCast(self, to: NSFetchRequest.self) - } - - - // MARK: NSFetchRequest - - @objc dynamic - override var affectedStores: [NSPersistentStore]? { - - get { - - return super.affectedStores - } - set { - - if #available(iOS 11.0, macOS 10.13, watchOS 4.0, tvOS 11.0, *) { - - self.copiedAffectedStores = (newValue as NSArray?)?.copy() as! NSArray? - super.affectedStores = newValue - return - } - // Bugfix for NSFetchRequest messing up memory management for `affectedStores` - // http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specified - if let releaseArray = self.releaseArray { - - releaseArray.release() - self.releaseArray = nil - } - self.copiedAffectedStores = (newValue as NSArray?)?.copy() as! NSArray? - super.affectedStores = newValue - self.releaseArray = (super.affectedStores as NSArray?).map(Unmanaged.passRetained(_:)) - } - } - - - // MARK: Private - - private var copiedAffectedStores: NSArray? - private var releaseArray: Unmanaged? -} diff --git a/Sources/CoreStoreFetchedResultsController.swift b/Sources/CoreStoreFetchedResultsController.swift deleted file mode 100644 index f7673fb..0000000 --- a/Sources/CoreStoreFetchedResultsController.swift +++ /dev/null @@ -1,99 +0,0 @@ -// -// CoreStoreFetchedResultsController.swift -// CoreStore -// -// Copyright © 2018 John Rommel Estropia -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -import Foundation -import CoreData - - -// MARK: - CoreStoreFetchedResultsController - -@available(macOS 10.12, *) -internal final class CoreStoreFetchedResultsController: NSFetchedResultsController { - - // MARK: Internal - - @nonobjc - internal let typedFetchRequest: CoreStoreFetchRequest - - @nonobjc - internal convenience init(dataStack: DataStack, fetchRequest: CoreStoreFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void) { - - self.init( - context: dataStack.mainContext, - fetchRequest: fetchRequest, - from: from, - sectionBy: sectionBy, - applyFetchClauses: applyFetchClauses - ) - } - - @nonobjc - internal init(context: NSManagedObjectContext, fetchRequest: CoreStoreFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void) { - - _ = try? from.applyToFetchRequest( - fetchRequest, - context: context, - applyAffectedStores: false - ) - applyFetchClauses(fetchRequest) - - self.typedFetchRequest = fetchRequest - self.reapplyAffectedStores = { fetchRequest, context in - - try from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) - } - - super.init( - fetchRequest: fetchRequest.staticCast(), - managedObjectContext: context, - sectionNameKeyPath: sectionBy?.sectionKeyPath, - cacheName: nil - ) - } - - @nonobjc - internal func performFetchFromSpecifiedStores() throws { - - try self.reapplyAffectedStores(self.typedFetchRequest, self.managedObjectContext) - try self.performFetch() - } - - @nonobjc - internal func dynamicCast() -> NSFetchedResultsController { - - return unsafeBitCast(self, to: NSFetchedResultsController.self) - } - - deinit { - - self.delegate = nil - } - - - // MARK: Private - - @nonobjc - private let reapplyAffectedStores: (_ fetchRequest: CoreStoreFetchRequest, _ context: NSManagedObjectContext) throws -> Void -} diff --git a/Sources/CoreStoreObject+Observing.swift b/Sources/CoreStoreObject+Observing.swift index 81d4365..50247f4 100644 --- a/Sources/CoreStoreObject+Observing.swift +++ b/Sources/CoreStoreObject+Observing.swift @@ -543,7 +543,7 @@ fileprivate final class _CoreStoreObjectKeyValueObservation: NSObject, CoreStore // workaround for Erroneous (?) error when using bridging in the Foundation overlay @nonobjc - static var swizzler: Any? = cs_lazy { + static var swizzler: Any? = Internals.with { let bridgeClass: AnyClass = _CoreStoreObjectKeyValueObservation.self let rootObserveImpl = class_getInstanceMethod( diff --git a/Sources/CoreStoreObject.swift b/Sources/CoreStoreObject.swift index 228ee58..beee31b 100644 --- a/Sources/CoreStoreObject.swift +++ b/Sources/CoreStoreObject.swift @@ -93,7 +93,7 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable { } if lhs.isMeta { - return cs_dynamicType(of: lhs) == cs_dynamicType(of: rhs) + return Internals.dynamicObjectType(of: lhs) == Internals.dynamicObjectType(of: rhs) } return lhs.rawObject!.isEqual(rhs.rawObject!) } @@ -147,9 +147,9 @@ extension DynamicObject where Self: CoreStoreObject { */ public func partialObject() -> PartialObject { - CoreStore.assert( + Internals.assert( !self.isMeta, - "Attempted to create a \(cs_typeName(PartialObject.self)) from a meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to create a \(Internals.typeName(PartialObject.self)) from a meta object. Meta objects are only used for querying keyPaths and infering types." ) return PartialObject(self.rawObject!) } diff --git a/Sources/CoreStoreSchema.swift b/Sources/CoreStoreSchema.swift index 0db2166..e2def5d 100644 --- a/Sources/CoreStoreSchema.swift +++ b/Sources/CoreStoreSchema.swift @@ -161,8 +161,8 @@ public final class CoreStoreSchema: DynamicSchema { let allEntities = Set(entityConfigurations.keys) actualEntitiesByConfiguration[DataStack.defaultConfigurationName] = allEntities - CoreStore.assert( - cs_lazy { + Internals.assert( + Internals.with { let expectedCount = allEntities.count return Set(allEntities.map({ ObjectIdentifier($0.type) })).count == expectedCount @@ -177,17 +177,17 @@ public final class CoreStoreSchema: DynamicSchema { if let versionLock = versionLock { - CoreStore.assert( + Internals.assert( versionLock == VersionLock(entityVersionHashesByName: self.rawModel().entityVersionHashesByName), - "A \(cs_typeName(VersionLock.self)) was provided for the \(cs_typeName(CoreStoreSchema.self)) with version \"\(modelVersion)\", but the actual hashes do not match. This may result in unwanted migrations or unusable persistent stores.\nExpected lock values: \(versionLock)\nActual lock values: \(VersionLock(entityVersionHashesByName: self.rawModel().entityVersionHashesByName))" + "A \(Internals.typeName(VersionLock.self)) was provided for the \(Internals.typeName(CoreStoreSchema.self)) with version \"\(modelVersion)\", but the actual hashes do not match. This may result in unwanted migrations or unusable persistent stores.\nExpected lock values: \(versionLock)\nActual lock values: \(VersionLock(entityVersionHashesByName: self.rawModel().entityVersionHashesByName))" ) } else { #if DEBUG - CoreStore.log( + Internals.log( .notice, - message: "These are hashes for the \(cs_typeName(CoreStoreSchema.self)) with version name \"\(modelVersion)\". Copy the dictionary below and pass it to the \(cs_typeName(CoreStoreSchema.self)) initializer's \"versionLock\" argument:\nversionLock: \(VersionLock(entityVersionHashesByName: self.rawModel().entityVersionHashesByName))" + message: "These are hashes for the \(Internals.typeName(CoreStoreSchema.self)) with version name \"\(modelVersion)\". Copy the dictionary below and pass it to the \(Internals.typeName(CoreStoreSchema.self)) initializer's \"versionLock\" argument:\nversionLock: \(VersionLock(entityVersionHashesByName: self.rawModel().entityVersionHashesByName))" ) #endif } @@ -288,7 +288,7 @@ public final class CoreStoreSchema: DynamicSchema { switch child.value { case let attribute as AttributeProtocol: - CoreStore.assert( + Internals.assert( !NSManagedObject.instancesRespond(to: Selector(attribute.keyPath)), "Attribute Property name \"\(String(reflecting: entity.type)).\(attribute.keyPath)\" is not allowed because it collides with \"\(String(reflecting: NSManagedObject.self)).\(attribute.keyPath)\"" ) @@ -306,7 +306,7 @@ public final class CoreStoreSchema: DynamicSchema { customGetterSetterByKeyPaths[attribute.keyPath] = (attribute.getter, attribute.setter) case let relationship as RelationshipProtocol: - CoreStore.assert( + Internals.assert( !NSManagedObject.instancesRespond(to: Selector(relationship.keyPath)), "Relationship Property name \"\(String(reflecting: entity.type)).\(relationship.keyPath)\" is not allowed because it collides with \"\(String(reflecting: NSManagedObject.self)).\(relationship.keyPath)\"" ) @@ -352,13 +352,13 @@ public final class CoreStoreSchema: DynamicSchema { } if matchedEntities.isEmpty { - CoreStore.abort( - "No \(cs_typeName("Entity<\(type)>")) instance found in the \(cs_typeName(CoreStoreSchema.self))." + Internals.abort( + "No \(Internals.typeName("Entity<\(type)>")) instance found in the \(Internals.typeName(CoreStoreSchema.self))." ) } else { - CoreStore.abort( + Internals.abort( "Ambiguous entity types or entity names were found in the model. Ensure that the entity types and entity names are unique to each other. Entities: \(matchedEntities)" ) } @@ -370,8 +370,8 @@ public final class CoreStoreSchema: DynamicSchema { return relationshipDescription } - CoreStore.abort( - "The inverse relationship for \"\(destinationEntity.type).\(destinationKeyPath)\" could not be found. Make sure to set the `inverse:` initializer argument for one of the paired \(cs_typeName("Relationship.ToOne")), \(cs_typeName("Relationship.ToManyOrdered")), or \(cs_typeName("Relationship.ToManyUnozrdered"))" + Internals.abort( + "The inverse relationship for \"\(destinationEntity.type).\(destinationKeyPath)\" could not be found. Make sure to set the `inverse:` initializer argument for one of the paired \(Internals.typeName("Relationship.ToOne")), \(Internals.typeName("Relationship.ToManyOrdered")), or \(Internals.typeName("Relationship.ToManyUnozrdered"))" ) } @@ -411,13 +411,13 @@ public final class CoreStoreSchema: DynamicSchema { for (name, relationshipDescription) in entityDescription.relationshipsByName { - CoreStore.assert( + Internals.assert( relationshipDescription.destinationEntity != nil, "The destination entity for relationship \"\(entity.type).\(name)\" could not be resolved." ) - CoreStore.assert( + Internals.assert( relationshipDescription.inverseRelationship != nil, - "The inverse relationship for \"\(entity.type).\(name)\" could not be found. Make sure to set the `inverse:` argument of the initializer for one of the paired \(cs_typeName("Relationship.ToOne")), \(cs_typeName("Relationship.ToManyOrdered")), or \(cs_typeName("Relationship.ToManyUnozrdered"))" + "The inverse relationship for \"\(entity.type).\(name)\" could not be found. Make sure to set the `inverse:` argument of the initializer for one of the paired \(Internals.typeName("Relationship.ToOne")), \(Internals.typeName("Relationship.ToManyOrdered")), or \(Internals.typeName("Relationship.ToManyUnozrdered"))" ) } } @@ -456,7 +456,7 @@ public final class CoreStoreSchema: DynamicSchema { let uniqueConstraints = entity.uniqueConstraints.filter({ !$0.isEmpty }) if !uniqueConstraints.isEmpty { - CoreStore.assert( + Internals.assert( entityDescription.superentity == nil, "Uniqueness constraints must be defined at the highest level possible." ) @@ -518,7 +518,7 @@ public final class CoreStoreSchema: DynamicSchema { customGetterSetterByKeyPaths: superEntity.coreStoreEntity.flatMap({ allCustomGettersSetters[$0] }) ) } - let superClass = cs_lazy { () -> CoreStoreManagedObject.Type in + let superClass = Internals.with { () -> CoreStoreManagedObject.Type in if let superClassName = superEntity?.managedObjectClassName, let superClass = NSClassFromString(superClassName) { @@ -562,7 +562,7 @@ public final class CoreStoreSchema: DynamicSchema { imp_implementationWithBlock(getter), "@@:") else { - CoreStore.abort("Could not dynamically add getter method \"\(getterName)\" to class \(cs_typeName(managedObjectClass))") + Internals.abort("Could not dynamically add getter method \"\(getterName)\" to class \(Internals.typeName(managedObjectClass))") } } if let setter = customGetterSetters.setter { @@ -574,7 +574,7 @@ public final class CoreStoreSchema: DynamicSchema { imp_implementationWithBlock(setter), "v@:@") else { - CoreStore.abort("Could not dynamically add setter method \"\(setterName)\" to class \(cs_typeName(managedObjectClass))") + Internals.abort("Could not dynamically add setter method \"\(setterName)\" to class \(Internals.typeName(managedObjectClass))") } } } diff --git a/Sources/CustomSchemaMappingProvider.swift b/Sources/CustomSchemaMappingProvider.swift index 505e530..f9d6aaa 100644 --- a/Sources/CustomSchemaMappingProvider.swift +++ b/Sources/CustomSchemaMappingProvider.swift @@ -53,8 +53,8 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider { */ public required init(from sourceVersion: ModelVersion, to destinationVersion: ModelVersion, entityMappings: Set = []) { - CoreStore.assert( - cs_lazy { + Internals.assert( + Internals.with { let sources = entityMappings.compactMap({ $0.entityMappingSourceEntity }) let destinations = entityMappings.compactMap({ $0.entityMappingDestinationEntity }) @@ -328,7 +328,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider { return lhs.sourceVersion == rhs.sourceVersion && lhs.destinationVersion == rhs.destinationVersion - && cs_dynamicType(of: lhs) == cs_dynamicType(of: rhs) + && Internals.dynamicObjectType(of: lhs) == Internals.dynamicObjectType(of: rhs) } @@ -338,7 +338,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider { hasher.combine(self.sourceVersion) hasher.combine(self.destinationVersion) - hasher.combine(ObjectIdentifier(cs_dynamicType(of: self))) + hasher.combine(ObjectIdentifier(Internals.dynamicObjectType(of: self))) } @@ -612,70 +612,70 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider { switch mapping { case .deleteEntity(let sourceEntity): - CoreStore.assert( + Internals.assert( sourceEntityNames[sourceEntity] != nil, - "A \(cs_typeName(CustomMapping.self)) with value '\(mapping)' passed to \(cs_typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(cs_typeName(NSEntityDescription.self)) from the source \(cs_typeName(NSManagedObjectModel.self))." + "A \(Internals.typeName(CustomMapping.self)) with value '\(mapping)' passed to \(Internals.typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(Internals.typeName(NSEntityDescription.self)) from the source \(Internals.typeName(NSManagedObjectModel.self))." ) - CoreStore.assert( + Internals.assert( allMappedSourceKeys[sourceEntity] == nil, - "Duplicate \(cs_typeName(CustomMapping.self))s found for source entity name \"\(sourceEntity)\" in \(cs_typeName(CustomSchemaMappingProvider.self))." + "Duplicate \(Internals.typeName(CustomMapping.self))s found for source entity name \"\(sourceEntity)\" in \(Internals.typeName(CustomSchemaMappingProvider.self))." ) deleteMappings.insert(mapping) allMappedSourceKeys[sourceEntity] = "" case .insertEntity(let destinationEntity): - CoreStore.assert( + Internals.assert( destinationEntityNames[destinationEntity] != nil, - "A \(cs_typeName(CustomMapping.self)) with value '\(mapping)' passed to \(cs_typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(cs_typeName(NSEntityDescription.self)) from the destination \(cs_typeName(NSManagedObjectModel.self))." + "A \(Internals.typeName(CustomMapping.self)) with value '\(mapping)' passed to \(Internals.typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(Internals.typeName(NSEntityDescription.self)) from the destination \(Internals.typeName(NSManagedObjectModel.self))." ) - CoreStore.assert( + Internals.assert( allMappedDestinationKeys[destinationEntity] == nil, - "Duplicate \(cs_typeName(CustomMapping.self))s found for destination entity name \"\(destinationEntity)\" in \(cs_typeName(CustomSchemaMappingProvider.self))." + "Duplicate \(Internals.typeName(CustomMapping.self))s found for destination entity name \"\(destinationEntity)\" in \(Internals.typeName(CustomSchemaMappingProvider.self))." ) insertMappings.insert(mapping) allMappedDestinationKeys[destinationEntity] = "" case .transformEntity(let sourceEntity, let destinationEntity, _): - CoreStore.assert( + Internals.assert( sourceEntityNames[sourceEntity] != nil, - "A \(cs_typeName(CustomMapping.self)) with value '\(mapping)' passed to \(cs_typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(cs_typeName(NSEntityDescription.self)) from the source \(cs_typeName(NSManagedObjectModel.self))." + "A \(Internals.typeName(CustomMapping.self)) with value '\(mapping)' passed to \(Internals.typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(Internals.typeName(NSEntityDescription.self)) from the source \(Internals.typeName(NSManagedObjectModel.self))." ) - CoreStore.assert( + Internals.assert( destinationEntityNames[destinationEntity] != nil, - "A \(cs_typeName(CustomMapping.self)) with value '\(mapping)' passed to \(cs_typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(cs_typeName(NSEntityDescription.self)) from the destination \(cs_typeName(NSManagedObjectModel.self))." + "A \(Internals.typeName(CustomMapping.self)) with value '\(mapping)' passed to \(Internals.typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(Internals.typeName(NSEntityDescription.self)) from the destination \(Internals.typeName(NSManagedObjectModel.self))." ) - CoreStore.assert( + Internals.assert( allMappedSourceKeys[sourceEntity] == nil, - "Duplicate \(cs_typeName(CustomMapping.self))s found for source entity name \"\(sourceEntity)\" in \(cs_typeName(CustomSchemaMappingProvider.self))." + "Duplicate \(Internals.typeName(CustomMapping.self))s found for source entity name \"\(sourceEntity)\" in \(Internals.typeName(CustomSchemaMappingProvider.self))." ) - CoreStore.assert( + Internals.assert( allMappedDestinationKeys[destinationEntity] == nil, - "Duplicate \(cs_typeName(CustomMapping.self))s found for destination entity name \"\(destinationEntity)\" in \(cs_typeName(CustomSchemaMappingProvider.self))." + "Duplicate \(Internals.typeName(CustomMapping.self))s found for destination entity name \"\(destinationEntity)\" in \(Internals.typeName(CustomSchemaMappingProvider.self))." ) transformMappings.insert(mapping) allMappedSourceKeys[sourceEntity] = destinationEntity allMappedDestinationKeys[destinationEntity] = sourceEntity case .copyEntity(let sourceEntity, let destinationEntity): - CoreStore.assert( + Internals.assert( sourceEntityNames[sourceEntity] != nil, - "A \(cs_typeName(CustomMapping.self)) with value '\(mapping)' passed to \(cs_typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(cs_typeName(NSEntityDescription.self)) from the source \(cs_typeName(NSManagedObjectModel.self))." + "A \(Internals.typeName(CustomMapping.self)) with value '\(mapping)' passed to \(Internals.typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(Internals.typeName(NSEntityDescription.self)) from the source \(Internals.typeName(NSManagedObjectModel.self))." ) - CoreStore.assert( + Internals.assert( destinationEntityNames[destinationEntity] != nil, - "A \(cs_typeName(CustomMapping.self)) with value '\(mapping)' passed to \(cs_typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(cs_typeName(NSEntityDescription.self)) from the destination \(cs_typeName(NSManagedObjectModel.self))." + "A \(Internals.typeName(CustomMapping.self)) with value '\(mapping)' passed to \(Internals.typeName(CustomSchemaMappingProvider.self)) could not be mapped to any \(Internals.typeName(NSEntityDescription.self)) from the destination \(Internals.typeName(NSManagedObjectModel.self))." ) - CoreStore.assert( + Internals.assert( sourceEntityNames[sourceEntity]!.versionHash == destinationEntityNames[destinationEntity]!.versionHash, - "A \(cs_typeName(CustomMapping.self)) with value '\(mapping)' was passed to \(cs_typeName(CustomSchemaMappingProvider.self)) but the \(cs_typeName(NSEntityDescription.self))'s \"versionHash\" of the source and destination entities do not match." + "A \(Internals.typeName(CustomMapping.self)) with value '\(mapping)' was passed to \(Internals.typeName(CustomSchemaMappingProvider.self)) but the \(Internals.typeName(NSEntityDescription.self))'s \"versionHash\" of the source and destination entities do not match." ) - CoreStore.assert( + Internals.assert( allMappedSourceKeys[sourceEntity] == nil, - "Duplicate \(cs_typeName(CustomMapping.self))s found for source entity name \"\(sourceEntity)\" in \(cs_typeName(CustomSchemaMappingProvider.self))." + "Duplicate \(Internals.typeName(CustomMapping.self))s found for source entity name \"\(sourceEntity)\" in \(Internals.typeName(CustomSchemaMappingProvider.self))." ) - CoreStore.assert( + Internals.assert( allMappedDestinationKeys[destinationEntity] == nil, - "Duplicate \(cs_typeName(CustomMapping.self))s found for destination entity name \"\(destinationEntity)\" in \(cs_typeName(CustomSchemaMappingProvider.self))." + "Duplicate \(Internals.typeName(CustomMapping.self))s found for destination entity name \"\(destinationEntity)\" in \(Internals.typeName(CustomSchemaMappingProvider.self))." ) copyMappings.insert(mapping) allMappedSourceKeys[sourceEntity] = destinationEntity diff --git a/Sources/DataStack+Migration.swift b/Sources/DataStack+Migration.swift index bda75e1..ab2eb75 100644 --- a/Sources/DataStack+Migration.swift +++ b/Sources/DataStack+Migration.swift @@ -76,9 +76,9 @@ extension DataStack { catch { let storeError = CoreStoreError(error) - CoreStore.log( + Internals.log( storeError, - "Failed to add \(cs_typeName(storage)) to the stack." + "Failed to add \(Internals.typeName(storage)) to the stack." ) DispatchQueue.main.async { @@ -108,9 +108,9 @@ extension DataStack { public func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) -> Progress? { let fileURL = storage.fileURL - CoreStore.assert( + Internals.assert( fileURL.isFileURL, - "The specified URL for the \(cs_typeName(storage)) is invalid: \"\(fileURL)\"" + "The specified URL for the \(Internals.typeName(storage)) is invalid: \"\(fileURL)\"" ) return self.coordinator.performSynchronously { @@ -137,9 +137,9 @@ extension DataStack { } let error = CoreStoreError.differentStorageExistsAtURL(existingPersistentStoreURL: fileURL) - CoreStore.log( + Internals.log( error, - "Failed to add \(cs_typeName(storage)) at \"\(fileURL)\" because a different \(cs_typeName(NSPersistentStore.self)) at that URL already exists." + "Failed to add \(Internals.typeName(storage)) at \"\(fileURL)\" because a different \(Internals.typeName(NSPersistentStore.self)) at that URL already exists." ) DispatchQueue.main.async { @@ -235,9 +235,9 @@ extension DataStack { catch { let storeError = CoreStoreError(error) - CoreStore.log( + Internals.log( storeError, - "Failed to load SQLite \(cs_typeName(NSPersistentStore.self)) metadata." + "Failed to load SQLite \(Internals.typeName(NSPersistentStore.self)) metadata." ) DispatchQueue.main.async { @@ -302,9 +302,9 @@ extension DataStack { } let error = CoreStoreError.differentStorageExistsAtURL(existingPersistentStoreURL: cacheFileURL) - CoreStore.log( + Internals.log( error, - "Failed to add \(cs_typeName(storage)) at \"\(cacheFileURL)\" because a different \(cs_typeName(NSPersistentStore.self)) at that URL already exists." + "Failed to add \(Internals.typeName(storage)) at \"\(cacheFileURL)\" because a different \(Internals.typeName(NSPersistentStore.self)) at that URL already exists." ) DispatchQueue.main.async { @@ -372,9 +372,9 @@ extension DataStack { catch { let storeError = CoreStoreError(error) - CoreStore.log( + Internals.log( storeError, - "Failed to load \(cs_typeName(NSPersistentStore.self)) metadata." + "Failed to load \(Internals.typeName(NSPersistentStore.self)) metadata." ) DispatchQueue.main.async { @@ -399,9 +399,9 @@ extension DataStack { let fileURL = storage.fileURL do { - CoreStore.assert( + Internals.assert( self.persistentStoreForStorage(storage) == nil, - "Attempted to migrate an already added \(cs_typeName(storage)) at URL \"\(fileURL)\"" + "Attempted to migrate an already added \(Internals.typeName(storage)) at URL \"\(fileURL)\"" ) let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStore( @@ -418,9 +418,9 @@ extension DataStack { catch { let metadataError = CoreStoreError(error) - CoreStore.log( + Internals.log( metadataError, - "Failed to load \(cs_typeName(storage)) metadata from URL \"\(fileURL)\"." + "Failed to load \(Internals.typeName(storage)) metadata from URL \"\(fileURL)\"." ) throw metadataError } @@ -440,9 +440,9 @@ extension DataStack { let fileURL = storage.fileURL - CoreStore.assert( + Internals.assert( self.persistentStoreForStorage(storage) == nil, - "Attempted to query required migrations for an already added \(cs_typeName(storage)) at URL \"\(fileURL)\"" + "Attempted to query required migrations for an already added \(Internals.typeName(storage)) at URL \"\(fileURL)\"" ) do { @@ -459,9 +459,9 @@ extension DataStack { targetModel: self.schemaHistory.rawModel, targetModelVersion: self.modelVersion ) - CoreStore.log( + Internals.log( error, - "Failed to find migration steps from the \(cs_typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\"." + "Failed to find migration steps from the \(Internals.typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\"." ) throw error } @@ -469,9 +469,9 @@ extension DataStack { if migrationSteps.count > 1 && storage.localStorageOptions.contains(.preventProgressiveMigration) { let error = CoreStoreError.progressiveMigrationRequired(localStoreURL: fileURL) - CoreStore.log( + Internals.log( error, - "Failed to find migration mapping from the \(cs_typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." + "Failed to find migration mapping from the \(Internals.typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." ) throw error } @@ -486,9 +486,9 @@ extension DataStack { catch { let metadataError = CoreStoreError(error) - CoreStore.log( + Internals.log( metadataError, - "Failed to load \(cs_typeName(storage)) metadata from URL \"\(fileURL)\"." + "Failed to load \(Internals.typeName(storage)) metadata from URL \"\(fileURL)\"." ) throw metadataError } @@ -507,9 +507,9 @@ extension DataStack { targetModel: self.schemaHistory.rawModel, targetModelVersion: self.modelVersion ) - CoreStore.log( + Internals.log( error, - "Failed to find migration steps from \(cs_typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.schemaHistory.rawModel)\"." + "Failed to find migration steps from \(Internals.typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.schemaHistory.rawModel)\"." ) DispatchQueue.main.async { @@ -532,9 +532,9 @@ extension DataStack { else if numberOfMigrations > 1 && storage.localStorageOptions.contains(.preventProgressiveMigration) { let error = CoreStoreError.progressiveMigrationRequired(localStoreURL: storage.fileURL) - CoreStore.log( + Internals.log( error, - "Failed to find migration mapping from the \(cs_typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." + "Failed to find migration mapping from the \(Internals.typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." ) DispatchQueue.main.async { @@ -582,7 +582,7 @@ extension DataStack { catch { let migrationError = CoreStoreError(error) - CoreStore.log( + Internals.log( migrationError, "Failed to migrate version model \"\(migrationType.sourceVersion)\" to version \"\(migrationType.destinationVersion)\"." ) @@ -778,7 +778,7 @@ extension DataStack { isDirectory: false ) - let migrationManager = MigrationManager( + let migrationManager = Internals.MigrationManager( sourceModel: sourceModel, destinationModel: destinationModel, progress: progress diff --git a/Sources/DataStack+Observing.swift b/Sources/DataStack+Observing.swift index c5a13b3..38f32b0 100644 --- a/Sources/DataStack+Observing.swift +++ b/Sources/DataStack+Observing.swift @@ -40,9 +40,9 @@ extension DataStack { */ public func monitorObject(_ object: D) -> ObjectMonitor { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) return ObjectMonitor(dataStack: self, object: object) } @@ -68,9 +68,9 @@ extension DataStack { */ public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) return ListMonitor( dataStack: self, @@ -80,9 +80,9 @@ extension DataStack { fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - CoreStore.assert( + Internals.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(Internals.typeName(ListMonitor.self)) requires a sort information. Specify from a \(Internals.typeName(OrderBy.self)) clause or any custom \(Internals.typeName(FetchClause.self)) that provides a sort descriptor." ) } ) @@ -126,9 +126,9 @@ extension DataStack { */ public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) _ = ListMonitor( dataStack: self, @@ -138,9 +138,9 @@ extension DataStack { fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - CoreStore.assert( + Internals.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(Internals.typeName(ListMonitor.self)) requires a sort information. Specify from a \(Internals.typeName(OrderBy.self)) clause or any custom \(Internals.typeName(FetchClause.self)) that provides a sort descriptor." ) }, createAsynchronously: createAsynchronously @@ -195,9 +195,9 @@ extension DataStack { */ public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) return ListMonitor( @@ -208,9 +208,9 @@ extension DataStack { fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - CoreStore.assert( + Internals.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(Internals.typeName(ListMonitor.self)) requires a sort information. Specify from a \(Internals.typeName(OrderBy.self)) clause or any custom \(Internals.typeName(FetchClause.self)) that provides a sort descriptor." ) } ) @@ -261,9 +261,9 @@ extension DataStack { */ public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." + "Attempted to observe objects from \(Internals.typeName(self)) outside the main thread." ) _ = ListMonitor( @@ -274,9 +274,9 @@ extension DataStack { fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - CoreStore.assert( + Internals.assert( fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(ListMonitor.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." + "An \(Internals.typeName(ListMonitor.self)) requires a sort information. Specify from a \(Internals.typeName(OrderBy.self)) clause or any custom \(Internals.typeName(FetchClause.self)) that provides a sort descriptor." ) }, createAsynchronously: createAsynchronously diff --git a/Sources/DataStack+Querying.swift b/Sources/DataStack+Querying.swift index 7a7a7ac..3a46102 100644 --- a/Sources/DataStack+Querying.swift +++ b/Sources/DataStack+Querying.swift @@ -87,9 +87,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchOne(from, fetchClauses) } @@ -104,9 +104,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchOne(from, fetchClauses) } @@ -126,9 +126,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchOne(clauseChain) } @@ -143,9 +143,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchAll(from, fetchClauses) } @@ -160,9 +160,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchAll(from, fetchClauses) } @@ -182,9 +182,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchAll(clauseChain) } @@ -199,9 +199,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) throws -> Int { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchCount(from, fetchClauses) } @@ -216,9 +216,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchCount(from, fetchClauses) } @@ -238,9 +238,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchCount(_ clauseChain: B) throws -> Int { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchCount(clauseChain) } @@ -255,9 +255,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchObjectID(from, fetchClauses) } @@ -272,9 +272,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchObjectID(from, fetchClauses) } @@ -294,9 +294,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchObjectID(clauseChain) } @@ -311,9 +311,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchObjectIDs(from, fetchClauses) } @@ -328,9 +328,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchObjectIDs(from, fetchClauses) } @@ -350,9 +350,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." + "Attempted to fetch from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.fetchObjectIDs(clauseChain) } @@ -373,9 +373,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> U? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to query from a \(cs_typeName(self)) outside the main thread." + "Attempted to query from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.queryValue(from, selectClause, queryClauses) } @@ -393,9 +393,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> U? { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to query from a \(cs_typeName(self)) outside the main thread." + "Attempted to query from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.queryValue(from, selectClause, queryClauses) } @@ -417,9 +417,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to query from a \(cs_typeName(self)) outside the main thread." + "Attempted to query from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } @@ -437,9 +437,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> [[String: Any]] { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to query from a \(cs_typeName(self)) outside the main thread." + "Attempted to query from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.queryAttributes(from, selectClause, queryClauses) } @@ -457,9 +457,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> [[String: Any]] { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to query from a \(cs_typeName(self)) outside the main thread." + "Attempted to query from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.queryAttributes(from, selectClause, queryClauses) } @@ -490,9 +490,9 @@ extension DataStack: FetchableSource, QueryableSource { */ public func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to query from a \(cs_typeName(self)) outside the main thread." + "Attempted to query from a \(Internals.typeName(self)) outside the main thread." ) return try self.mainContext.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } diff --git a/Sources/DataStack+Transaction.swift b/Sources/DataStack+Transaction.swift index ab35ca6..a7eae2d 100644 --- a/Sources/DataStack+Transaction.swift +++ b/Sources/DataStack+Transaction.swift @@ -158,7 +158,7 @@ extension DataStack { */ public func refreshAndMergeAllObjects() { - CoreStore.assert( + Internals.assert( Thread.isMainThread, "Attempted to refresh entities outside their designated queue." ) diff --git a/Sources/DataStack.swift b/Sources/DataStack.swift index 6a320c2..5336566 100644 --- a/Sources/DataStack.swift +++ b/Sources/DataStack.swift @@ -193,7 +193,7 @@ public final class DataStack: Equatable { */ public func entityDescription(for type: NSManagedObject.Type) -> NSEntityDescription? { - return self.entityDescription(for: EntityIdentifier(type)) + return self.entityDescription(for: Internals.EntityIdentifier(type)) } /** @@ -201,7 +201,7 @@ public final class DataStack: Equatable { */ public func entityDescription(for type: CoreStoreObject.Type) -> NSEntityDescription? { - return self.entityDescription(for: EntityIdentifier(type)) + return self.entityDescription(for: Internals.EntityIdentifier(type)) } /** @@ -257,9 +257,9 @@ public final class DataStack: Equatable { catch { let storeError = CoreStoreError(error) - CoreStore.log( + Internals.log( storeError, - "Failed to add \(cs_typeName(storage)) to the stack." + "Failed to add \(Internals.typeName(storage)) to the stack." ) throw storeError } @@ -280,9 +280,9 @@ public final class DataStack: Equatable { return try self.coordinator.performSynchronously { let fileURL = storage.fileURL - CoreStore.assert( + Internals.assert( fileURL.isFileURL, - "The specified store URL for the \"\(cs_typeName(storage))\" is invalid: \"\(fileURL)\"" + "The specified store URL for the \"\(Internals.typeName(storage))\" is invalid: \"\(fileURL)\"" ) if let _ = self.persistentStoreForStorage(storage) { @@ -299,9 +299,9 @@ public final class DataStack: Equatable { } let error = CoreStoreError.differentStorageExistsAtURL(existingPersistentStoreURL: fileURL) - CoreStore.log( + Internals.log( error, - "Failed to add \(cs_typeName(storage)) at \"\(fileURL)\" because a different \(cs_typeName(NSPersistentStore.self)) at that URL already exists." + "Failed to add \(Internals.typeName(storage)) at \"\(fileURL)\" because a different \(Internals.typeName(NSPersistentStore.self)) at that URL already exists." ) throw error } @@ -351,9 +351,9 @@ public final class DataStack: Equatable { localStoreURL: fileURL, NSError: error ) - CoreStore.log( + Internals.log( storeError, - "Failed to add \(cs_typeName(storage)) to the stack." + "Failed to add \(Internals.typeName(storage)) to the stack." ) throw storeError } @@ -361,9 +361,9 @@ public final class DataStack: Equatable { catch { let storeError = CoreStoreError(error) - CoreStore.log( + Internals.log( storeError, - "Failed to add \(cs_typeName(storage)) to the stack." + "Failed to add \(Internals.typeName(storage)) to the stack." ) throw storeError } @@ -410,9 +410,9 @@ public final class DataStack: Equatable { } let error = CoreStoreError.differentStorageExistsAtURL(existingPersistentStoreURL: cacheFileURL) - CoreStore.log( + Internals.log( error, - "Failed to add \(cs_typeName(storage)) at \"\(cacheFileURL)\" because a different \(cs_typeName(NSPersistentStore.self)) at that URL already exists." + "Failed to add \(Internals.typeName(storage)) at \"\(cacheFileURL)\" because a different \(Internals.typeName(NSPersistentStore.self)) at that URL already exists." ) throw error } @@ -454,9 +454,9 @@ public final class DataStack: Equatable { catch { let storeError = CoreStoreError(error) - CoreStore.log( + Internals.log( storeError, - "Failed to add \(cs_typeName(storage)) to the stack." + "Failed to add \(Internals.typeName(storage)) to the stack." ) throw storeError } @@ -497,7 +497,7 @@ public final class DataStack: Equatable { internal let schemaHistory: SchemaHistory internal let childTransactionQueue = DispatchQueue.serial("com.coreStore.dataStack.childTransactionQueue") internal let storeMetadataUpdateQueue = DispatchQueue.concurrent("com.coreStore.persistentStoreBarrierQueue") - internal let migrationQueue: OperationQueue = cs_lazy { + internal let migrationQueue: OperationQueue = Internals.with { let migrationQueue = OperationQueue() migrationQueue.maxConcurrentOperationCount = 1 @@ -514,7 +514,7 @@ public final class DataStack: Equatable { .first } - internal func persistentStores(for entityIdentifier: EntityIdentifier) -> [NSPersistentStore]? { + internal func persistentStores(for entityIdentifier: Internals.EntityIdentifier) -> [NSPersistentStore]? { var returnValue: [NSPersistentStore]? = nil self.storeMetadataUpdateQueue.sync(flags: .barrier) { @@ -525,7 +525,7 @@ public final class DataStack: Equatable { return returnValue } - internal func persistentStore(for entityIdentifier: EntityIdentifier, configuration: ModelConfiguration, inferStoreIfPossible: Bool) -> (store: NSPersistentStore?, isAmbiguous: Bool) { + internal func persistentStore(for entityIdentifier: Internals.EntityIdentifier, configuration: ModelConfiguration, inferStoreIfPossible: Bool) -> (store: NSPersistentStore?, isAmbiguous: Bool) { return self.storeMetadataUpdateQueue.sync(flags: .barrier) { () -> (store: NSPersistentStore?, isAmbiguous: Bool) in @@ -573,11 +573,11 @@ public final class DataStack: Equatable { for entityDescription in (self.coordinator.managedObjectModel.entities(forConfigurationName: configurationName) ?? []) { let managedObjectClassName = entityDescription.managedObjectClassName! - CoreStore.assert( + Internals.assert( NSClassFromString(managedObjectClassName) != nil, - "The class \(cs_typeName(managedObjectClassName)) for the entity \(cs_typeName(entityDescription.name)) does not exist. Check if the subclass type and module name are properly configured." + "The class \(Internals.typeName(managedObjectClassName)) for the entity \(Internals.typeName(entityDescription.name)) does not exist. Check if the subclass type and module name are properly configured." ) - let entityIdentifier = EntityIdentifier(entityDescription) + let entityIdentifier = Internals.EntityIdentifier(entityDescription) if self.finalConfigurationsByEntityIdentifier[entityIdentifier] == nil { self.finalConfigurationsByEntityIdentifier[entityIdentifier] = [] @@ -589,7 +589,7 @@ public final class DataStack: Equatable { return persistentStore } - internal func entityDescription(for entityIdentifier: EntityIdentifier) -> NSEntityDescription? { + internal func entityDescription(for entityIdentifier: Internals.EntityIdentifier) -> NSEntityDescription? { return self.schemaHistory.entityDescriptionsByEntityIdentifier[entityIdentifier] } @@ -598,7 +598,7 @@ public final class DataStack: Equatable { // MARK: Private private var persistentStoresByFinalConfiguration = [String: NSPersistentStore]() - private var finalConfigurationsByEntityIdentifier = [EntityIdentifier: Set]() + private var finalConfigurationsByEntityIdentifier = [Internals.EntityIdentifier: Set]() deinit { diff --git a/Sources/DynamicObject.swift b/Sources/DynamicObject.swift index 923ea43..6841873 100644 --- a/Sources/DynamicObject.swift +++ b/Sources/DynamicObject.swift @@ -60,6 +60,16 @@ public protocol DynamicObject: AnyObject { func cs_toRaw() -> NSManagedObject } +extension DynamicObject { + + // MARK: Internal + + internal static func keyPathBuilder() -> DynamicObjectMeta { + + return .init(keyPathString: "SELF") + } +} + // MARK: - NSManagedObject diff --git a/Sources/DynamicObjectMeta.swift b/Sources/DynamicObjectMeta.swift new file mode 100644 index 0000000..dec8602 --- /dev/null +++ b/Sources/DynamicObjectMeta.swift @@ -0,0 +1,143 @@ +// +// DynamicObjectMeta.swift +// CoreStore iOS +// +// Created by John Estropia on 2019/08/20. +// Copyright © 2019 John Rommel Estropia. All rights reserved. +// + +#if swift(>=5.1) + +import CoreData +import Foundation + + +// MARK: - DynamicObjectMeta + +@dynamicMemberLookup +public struct DynamicObjectMeta: CustomDebugStringConvertible { + + // MARK: Public + + public typealias Root = R + public typealias Destination = D + + + // MARK: CustomDebugStringConvertible + + public var debugDescription: String { + + return self.keyPathString + } + + + // MARK: Internal + + internal let keyPathString: KeyPathString + + internal init(keyPathString: KeyPathString) { + + self.keyPathString = keyPathString + } + + internal func appending(keyPathString: KeyPathString) -> DynamicObjectMeta<(R, D), D2> { + + return .init(keyPathString: [self.keyPathString, keyPathString].joined(separator: ".")) + } +} + + +// MARK: - DynamicObjectMeta where Destination: NSManagedObject + +extension DynamicObjectMeta where Destination: NSManagedObject { + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), V.ReturnValueType> { + + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), V> { + + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), V> { + + // TODO: not working + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), V> { + + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), V> { + + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), V> { + + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), V> { + + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } +} + + +// MARK: - DynamicObjectMeta where Destination: CoreStoreObject + +extension DynamicObjectMeta where Destination: CoreStoreObject { + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), K.ReturnValueType> { + + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } + + /** + Returns the value for the property identified by a given key. + */ + public subscript(dynamicMember member: KeyPath) -> DynamicObjectMeta<(Root, Destination), K.DestinationValueType> { + + let keyPathString = String(keyPath: member) + return self.appending(keyPathString: keyPathString) + } +} + +#endif diff --git a/Sources/EntityIdentifier.swift b/Sources/EntityIdentifier.swift deleted file mode 100644 index 4975214..0000000 --- a/Sources/EntityIdentifier.swift +++ /dev/null @@ -1,88 +0,0 @@ -// -// EntityIdentifier.swift -// CoreStore -// -// Copyright © 2018 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: - EntityIdentifier - -internal struct EntityIdentifier: Hashable { - - // MARK: - Category - - internal enum Category: Int { - - case coreData - case coreStore - } - - - // MARK: - - - internal let category: Category - internal let interfacedClassName: String - - internal init(_ type: NSManagedObject.Type) { - - self.category = .coreData - self.interfacedClassName = NSStringFromClass(type) - } - - internal init(_ type: CoreStoreObject.Type) { - - self.category = .coreStore - self.interfacedClassName = NSStringFromClass(type) - } - - internal init(_ type: DynamicObject.Type) { - - switch type { - - case let type as NSManagedObject.Type: - self.init(type) - - case let type as CoreStoreObject.Type: - self.init(type) - - default: - CoreStore.abort("\(cs_typeName(DynamicObject.self)) is not meant to be implemented by external types.") - } - } - - internal init(_ entityDescription: NSEntityDescription) { - - if let anyEntity = entityDescription.coreStoreEntity { - - self.category = .coreStore - self.interfacedClassName = NSStringFromClass(anyEntity.type) - } - else { - - self.category = .coreData - self.interfacedClassName = entityDescription.managedObjectClassName! - } - } -} diff --git a/Sources/FetchedResultsControllerDelegate.swift b/Sources/FetchedResultsControllerDelegate.swift deleted file mode 100644 index 417573e..0000000 --- a/Sources/FetchedResultsControllerDelegate.swift +++ /dev/null @@ -1,266 +0,0 @@ -// -// FetchedResultsControllerDelegate.swift -// CoreStore -// -// Copyright © 2018 John Rommel Estropia -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -import Foundation -import CoreData - - -// MARK: - FetchedResultsControllerHandler - -@available(macOS 10.12, *) -internal protocol FetchedResultsControllerHandler: AnyObject { - - func controller(_ controller: NSFetchedResultsController, didChangeObject anObject: Any, atIndexPath indexPath: IndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) - - func controller(_ controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) - - func controllerWillChangeContent(_ controller: NSFetchedResultsController) - - func controllerDidChangeContent(_ controller: NSFetchedResultsController) - - func controller(_ controller: NSFetchedResultsController, sectionIndexTitleForSectionName sectionName: String?) -> String? -} - - -// MARK: - FetchedResultsControllerDelegate - -@available(macOS 10.12, *) -internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResultsControllerDelegate { - - // MARK: Internal - - @nonobjc - internal var enabled = true - - @nonobjc - internal let taskGroup = DispatchGroup() - - @nonobjc - internal weak var handler: FetchedResultsControllerHandler? - - @nonobjc - internal weak var fetchedResultsController: CoreStoreFetchedResultsController? { - - didSet { - - oldValue?.delegate = nil - self.fetchedResultsController?.delegate = self - } - } - - deinit { - - self.fetchedResultsController?.delegate = nil - } - - - // MARK: NSFetchedResultsControllerDelegate - - @objc - dynamic func controllerWillChangeContent(_ controller: NSFetchedResultsController) { - - self.taskGroup.enter() - guard self.enabled else { - - return - } - - if #available(iOS 10.3, tvOS 10.3, watchOS 3.2, macOS 10.13, *) {} - else { - - self.deletedSections = [] - self.insertedSections = [] - } - - self.handler?.controllerWillChangeContent(controller) - } - - @objc - dynamic func controllerDidChangeContent(_ controller: NSFetchedResultsController) { - - defer { - - self.taskGroup.leave() - } - guard self.enabled else { - - return - } - - self.handler?.controllerDidChangeContent(controller) - } - - @objc - dynamic func controller(_ controller: NSFetchedResultsController, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) { - - guard self.enabled else { - - return - } - - if #available(iOS 10.3, tvOS 10.3, watchOS 3.2, macOS 10.13, *) { - - self.handler?.controller( - controller, - didChangeObject: anObject, - atIndexPath: indexPath, - forChangeType: type, - newIndexPath: newIndexPath - ) - return - } - - guard var actualType = NSFetchedResultsChangeType(rawValue: type.rawValue) else { - - // This fix is for a bug where iOS passes 0 for NSFetchedResultsChangeType, but this is not a valid enum case. - // Swift will then always execute the first case of the switch causing strange behaviour. - // https://forums.developer.apple.com/thread/12184#31850 - return - } - - // This whole dance is a workaround for a nasty bug introduced in XCode 7 targeted at iOS 8 devices - // http://stackoverflow.com/questions/31383760/ios-9-attempt-to-delete-and-reload-the-same-index-path/31384014#31384014 - // https://forums.developer.apple.com/message/9998#9998 - // https://forums.developer.apple.com/message/31849#31849 - - if case .update = actualType, - indexPath != nil, - newIndexPath != nil { - - actualType = .move - } - - switch actualType { - - case .update: - guard let section = indexPath?[0] else { - - return - } - if self.deletedSections.contains(section) - || self.insertedSections.contains(section) { - - return - } - - case .move: - guard let indexPath = indexPath, let newIndexPath = newIndexPath else { - - return - } - guard indexPath == newIndexPath else { - - break - } - if self.insertedSections.contains(indexPath[0]) { - - // Observers that handle the .Move change are advised to delete then reinsert the object instead of just moving. This is especially true when indexPath and newIndexPath are equal. For example, calling tableView.moveRowAtIndexPath(_:toIndexPath) when both indexPaths are the same will crash the tableView. - self.handler?.controller( - controller, - didChangeObject: anObject, - atIndexPath: indexPath, - forChangeType: .move, - newIndexPath: newIndexPath - ) - return - } - if self.deletedSections.contains(indexPath[0]) { - - self.handler?.controller( - controller, - didChangeObject: anObject, - atIndexPath: nil, - forChangeType: .insert, - newIndexPath: indexPath - ) - return - } - self.handler?.controller( - controller, - didChangeObject: anObject, - atIndexPath: indexPath, - forChangeType: .update, - newIndexPath: nil - ) - return - - default: - break - } - - self.handler?.controller( - controller, - didChangeObject: anObject, - atIndexPath: indexPath, - forChangeType: actualType, - newIndexPath: newIndexPath - ) - } - - @objc - dynamic func controller(_ controller: NSFetchedResultsController, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) { - - guard self.enabled else { - - return - } - - if #available(iOS 10.3, tvOS 10.3, watchOS 3.2, macOS 10.13, *) {} - else { - - switch type { - - case .delete: self.deletedSections.insert(sectionIndex) - case .insert: self.insertedSections.insert(sectionIndex) - default: break - } - } - - self.handler?.controller( - controller, - didChangeSection: sectionInfo, - atIndex: sectionIndex, - forChangeType: type - ) - } - - @objc - dynamic func controller(_ controller: NSFetchedResultsController, sectionIndexTitleForSectionName sectionName: String) -> String? { - - return self.handler?.controller( - controller, - sectionIndexTitleForSectionName: sectionName - ) - } - - - // MARK: Private - - @nonobjc - private var deletedSections = Set() - - @nonobjc - private var insertedSections = Set() -} diff --git a/Sources/From.swift b/Sources/From.swift index 5a9b778..5eaaa35 100644 --- a/Sources/From.swift +++ b/Sources/From.swift @@ -139,17 +139,17 @@ public struct From { self.findPersistentStores = findPersistentStores } - internal func applyToFetchRequest(_ fetchRequest: CoreStoreFetchRequest, context: NSManagedObjectContext, applyAffectedStores: Bool = true) throws { + internal func applyToFetchRequest(_ fetchRequest: Internals.CoreStoreFetchRequest, context: NSManagedObjectContext, applyAffectedStores: Bool = true) throws { guard let parentStack = context.parentStack else { - CoreStore.log( + Internals.log( .warning, - message: "Attempted to perform a fetch but the \(cs_typeName(DataStack.self)) has already been deallocated." + message: "Attempted to perform a fetch but the \(Internals.typeName(DataStack.self)) has already been deallocated." ) throw CoreStoreError.unknown } - fetchRequest.entity = parentStack.entityDescription(for: EntityIdentifier(self.entityClass))! + fetchRequest.entity = parentStack.entityDescription(for: Internals.EntityIdentifier(self.entityClass))! guard applyAffectedStores else { return @@ -160,9 +160,9 @@ public struct From { } catch let error as CoreStoreError { - CoreStore.log( + Internals.log( error, - "Attempted to perform a fetch but could not find any persistent store for the entity \(cs_typeName(fetchRequest.entityName))" + "Attempted to perform a fetch but could not find any persistent store for the entity \(Internals.typeName(fetchRequest.entityName))" ) throw error } @@ -172,7 +172,7 @@ public struct From { } } - internal func applyAffectedStoresForFetchedRequest(_ fetchRequest: CoreStoreFetchRequest, context: NSManagedObjectContext) throws { + internal func applyAffectedStoresForFetchedRequest(_ fetchRequest: Internals.CoreStoreFetchRequest, context: NSManagedObjectContext) throws { let stores = self.findPersistentStores(context) fetchRequest.affectedStores = stores @@ -191,7 +191,7 @@ public struct From { self.entityClass = entityClass self.configurations = configurations - let entityIdentifier = EntityIdentifier(entityClass) + let entityIdentifier = Internals.EntityIdentifier(entityClass) if let configurations = configurations { let configurationsSet = Set(configurations.map({ $0 ?? DataStack.defaultConfigurationName })) diff --git a/Sources/Functions.swift b/Sources/Functions.swift deleted file mode 100644 index 7cc83dc..0000000 --- a/Sources/Functions.swift +++ /dev/null @@ -1,120 +0,0 @@ -// -// Functions.swift -// CoreStore -// -// Copyright © 2018 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 - -// MARK: Associated Objects - -@inline(__always) -/// type(of:) doesn't return the dynamic type anymore, use this to guarantee correct dispatch of class methods -internal func cs_dynamicType(of instance: T) -> T.Type { - - return object_getClass(instance) as! T.Type -} - -// MARK: Associated Objects - -@inline(__always) -internal func cs_getAssociatedObjectForKey(_ key: UnsafeRawPointer, inObject object: Any) -> T? { - - switch objc_getAssociatedObject(object, key) { - - case let associatedObject as T: - return associatedObject - - case let associatedObject as WeakObject: - return associatedObject.object as? T - - default: - return nil - } -} - -@inline(__always) -internal func cs_setAssociatedRetainedObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: Any) { - - objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) -} - -@inline(__always) -internal func cs_setAssociatedCopiedObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: Any) { - - objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_COPY_NONATOMIC) -} - -@inline(__always) -internal func cs_setAssociatedWeakObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: Any) { - - if let associatedObject = associatedObject { - - objc_setAssociatedObject(object, key, WeakObject(associatedObject), .OBJC_ASSOCIATION_RETAIN_NONATOMIC) - } - else { - - objc_setAssociatedObject(object, key, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) - } -} - - -// MARK: Printing Utilities - -@inline(__always) -internal func cs_typeName(_ value: T) -> String { - - return "'\(String(reflecting: type(of: value)))'" -} - -@inline(__always) -internal func cs_typeName(_ value: T.Type) -> String { - - return "'\(value)'" -} - -@inline(__always) -internal func cs_typeName(_ value: AnyClass) -> String { - - return "'\(value)'" -} - -@inline(__always) -internal func cs_typeName(_ name: String) -> String { - - return "<\(name)>" -} - -@inline(__always) -internal func cs_typeName(_ name: String?) -> String { - - return "<\(name ?? "unknown")>" -} - - -// MARK: Functional - -@inline(__always) -internal func cs_lazy(_ closure: () -> T) -> T { - - return closure() -} diff --git a/Sources/GroupBy.swift b/Sources/GroupBy.swift index d1c75fa..a4750e1 100644 --- a/Sources/GroupBy.swift +++ b/Sources/GroupBy.swift @@ -77,9 +77,9 @@ public struct GroupBy: GroupByClause, QueryClause, Hashable { if let keyPaths = fetchRequest.propertiesToGroupBy as? [String], keyPaths != self.keyPaths { - CoreStore.log( + Internals.log( .warning, - message: "An existing \"propertiesToGroupBy\" for the \(cs_typeName(NSFetchRequest.self)) was overwritten by \(cs_typeName(self)) query clause." + message: "An existing \"propertiesToGroupBy\" for the \(Internals.typeName(NSFetchRequest.self)) was overwritten by \(Internals.typeName(self)) query clause." ) } diff --git a/Sources/ImportableUniqueObject.swift b/Sources/ImportableUniqueObject.swift index db8b915..ab49247 100644 --- a/Sources/ImportableUniqueObject.swift +++ b/Sources/ImportableUniqueObject.swift @@ -125,7 +125,7 @@ extension ImportableUniqueObject where UniqueIDType.QueryableNativeType: CoreDat get { return self.cs_toRaw().getValue( - forKvcKey: cs_dynamicType(of: self).uniqueIDKeyPath, + forKvcKey: Internals.dynamicObjectType(of: self).uniqueIDKeyPath, didGetValue: { UniqueIDType.cs_fromQueryableNativeType($0 as! UniqueIDType.QueryableNativeType)! } ) } @@ -134,7 +134,7 @@ extension ImportableUniqueObject where UniqueIDType.QueryableNativeType: CoreDat self.cs_toRaw() .setValue( newValue, - forKvcKey: cs_dynamicType(of: self).uniqueIDKeyPath, + forKvcKey: Internals.dynamicObjectType(of: self).uniqueIDKeyPath, willSetValue: { ($0.cs_toQueryableNativeType() as CoreDataNativeType) } ) } diff --git a/Sources/InferredSchemaMappingProvider.swift b/Sources/InferredSchemaMappingProvider.swift index db14b59..4ecc942 100644 --- a/Sources/InferredSchemaMappingProvider.swift +++ b/Sources/InferredSchemaMappingProvider.swift @@ -88,9 +88,9 @@ public final class InferredSchemaMappingProvider: Hashable, SchemaMappingProvide catch { let coreStoreError = CoreStoreError(error) - CoreStore.log( + Internals.log( coreStoreError, - "\(cs_typeName(self)) failed to find migration mappings from version model \"\(sourceSchema.modelVersion)\" to \"\(destinationSchema.modelVersion)\" in the \(cs_typeName(storage)) at URL \"\(storage.fileURL)\". The local storage may be corrupt or the \(cs_typeName(storage)) initializer may be missing the correct \(cs_typeName(SchemaMappingProvider.self))" + "\(Internals.typeName(self)) failed to find migration mappings from version model \"\(sourceSchema.modelVersion)\" to \"\(destinationSchema.modelVersion)\" in the \(Internals.typeName(storage)) at URL \"\(storage.fileURL)\". The local storage may be corrupt or the \(Internals.typeName(storage)) initializer may be missing the correct \(Internals.typeName(SchemaMappingProvider.self))" ) throw coreStoreError } diff --git a/Sources/Internals.CoreStoreFetchRequest.swift b/Sources/Internals.CoreStoreFetchRequest.swift new file mode 100644 index 0000000..aaf43f7 --- /dev/null +++ b/Sources/Internals.CoreStoreFetchRequest.swift @@ -0,0 +1,96 @@ +// +// CoreStoreFetchRequest.swift +// CoreStore +// +// Copyright © 2019 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 +import ObjectiveC + + +// MARK: - Internal + +extension Internals { + + // MARK: - CoreStoreFetchRequest + + // Bugfix for NSFetchRequest messing up memory management for `affectedStores` + // http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specified + internal final class CoreStoreFetchRequest: NSFetchRequest { + + @nonobjc + internal func safeAffectedStores() -> [NSPersistentStore]? { + + return self.copiedAffectedStores as! [NSPersistentStore]? + } + + @nonobjc @inline(__always) + internal func staticCast() -> NSFetchRequest { + + return unsafeBitCast(self, to: NSFetchRequest.self) + } + + @nonobjc @inline(__always) + internal func dynamicCast() -> NSFetchRequest { + + return unsafeBitCast(self, to: NSFetchRequest.self) + } + + + // MARK: NSFetchRequest + + @objc dynamic + override var affectedStores: [NSPersistentStore]? { + + get { + + return super.affectedStores + } + set { + + if #available(iOS 11.0, macOS 10.13, watchOS 4.0, tvOS 11.0, *) { + + self.copiedAffectedStores = (newValue as NSArray?)?.copy() as! NSArray? + super.affectedStores = newValue + return + } + // Bugfix for NSFetchRequest messing up memory management for `affectedStores` + // http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specified + if let releaseArray = self.releaseArray { + + releaseArray.release() + self.releaseArray = nil + } + self.copiedAffectedStores = (newValue as NSArray?)?.copy() as! NSArray? + super.affectedStores = newValue + self.releaseArray = (super.affectedStores as NSArray?).map(Unmanaged.passRetained(_:)) + } + } + + + // MARK: Private + + private var copiedAffectedStores: NSArray? + private var releaseArray: Unmanaged? + } +} diff --git a/Sources/Internals.CoreStoreFetchedResultsController.swift b/Sources/Internals.CoreStoreFetchedResultsController.swift new file mode 100644 index 0000000..4db2239 --- /dev/null +++ b/Sources/Internals.CoreStoreFetchedResultsController.swift @@ -0,0 +1,104 @@ +// +// CoreStoreFetchedResultsController.swift +// CoreStore +// +// Copyright © 2018 John Rommel Estropia +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation +import CoreData + + +// MARK: - Internals + +extension Internals { + + // MARK: - CoreStoreFetchedResultsController + + @available(macOS 10.12, *) + internal final class CoreStoreFetchedResultsController: NSFetchedResultsController { + + // MARK: Internal + + @nonobjc + internal let typedFetchRequest: Internals.CoreStoreFetchRequest + + @nonobjc + internal convenience init(dataStack: DataStack, fetchRequest: Internals.CoreStoreFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void) { + + self.init( + context: dataStack.mainContext, + fetchRequest: fetchRequest, + from: from, + sectionBy: sectionBy, + applyFetchClauses: applyFetchClauses + ) + } + + @nonobjc + internal init(context: NSManagedObjectContext, fetchRequest: Internals.CoreStoreFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void) { + + _ = try? from.applyToFetchRequest( + fetchRequest, + context: context, + applyAffectedStores: false + ) + applyFetchClauses(fetchRequest) + + self.typedFetchRequest = fetchRequest + self.reapplyAffectedStores = { fetchRequest, context in + + try from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) + } + + super.init( + fetchRequest: fetchRequest.staticCast(), + managedObjectContext: context, + sectionNameKeyPath: sectionBy?.sectionKeyPath, + cacheName: nil + ) + } + + @nonobjc + internal func performFetchFromSpecifiedStores() throws { + + try self.reapplyAffectedStores(self.typedFetchRequest, self.managedObjectContext) + try self.performFetch() + } + + @nonobjc + internal func dynamicCast() -> NSFetchedResultsController { + + return unsafeBitCast(self, to: NSFetchedResultsController.self) + } + + deinit { + + self.delegate = nil + } + + + // MARK: Private + + @nonobjc + private let reapplyAffectedStores: (_ fetchRequest: Internals.CoreStoreFetchRequest, _ context: NSManagedObjectContext) throws -> Void + } +} diff --git a/Sources/Internals.EntityIdentifier.swift b/Sources/Internals.EntityIdentifier.swift new file mode 100644 index 0000000..6d3e45e --- /dev/null +++ b/Sources/Internals.EntityIdentifier.swift @@ -0,0 +1,93 @@ +// +// Internals.EntityIdentifier.swift +// CoreStore +// +// Copyright © 2018 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: - Internal + +extension Internals { + + // MARK: - EntityIdentifier + + internal struct EntityIdentifier: Hashable { + + // MARK: - Category + + internal enum Category: Int { + + case coreData + case coreStore + } + + + // MARK: - + + internal let category: Category + internal let interfacedClassName: String + + internal init(_ type: NSManagedObject.Type) { + + self.category = .coreData + self.interfacedClassName = NSStringFromClass(type) + } + + internal init(_ type: CoreStoreObject.Type) { + + self.category = .coreStore + self.interfacedClassName = NSStringFromClass(type) + } + + internal init(_ type: DynamicObject.Type) { + + switch type { + + case let type as NSManagedObject.Type: + self.init(type) + + case let type as CoreStoreObject.Type: + self.init(type) + + default: + Internals.abort("\(Internals.typeName(DynamicObject.self)) is not meant to be implemented by external types.") + } + } + + internal init(_ entityDescription: NSEntityDescription) { + + if let anyEntity = entityDescription.coreStoreEntity { + + self.category = .coreStore + self.interfacedClassName = NSStringFromClass(anyEntity.type) + } + else { + + self.category = .coreData + self.interfacedClassName = entityDescription.managedObjectClassName! + } + } + } +} diff --git a/Sources/Internals.FetchedResultsControllerDelegate.swift b/Sources/Internals.FetchedResultsControllerDelegate.swift new file mode 100644 index 0000000..2f88035 --- /dev/null +++ b/Sources/Internals.FetchedResultsControllerDelegate.swift @@ -0,0 +1,271 @@ +// +// Internals.FetchedResultsControllerDelegate.swift +// CoreStore +// +// Copyright © 2018 John Rommel Estropia +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation +import CoreData + + +// MARK: - FetchedResultsControllerHandler + +@available(macOS 10.12, *) +internal protocol FetchedResultsControllerHandler: AnyObject { + + func controller(_ controller: NSFetchedResultsController, didChangeObject anObject: Any, atIndexPath indexPath: IndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) + + func controller(_ controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) + + func controllerWillChangeContent(_ controller: NSFetchedResultsController) + + func controllerDidChangeContent(_ controller: NSFetchedResultsController) + + func controller(_ controller: NSFetchedResultsController, sectionIndexTitleForSectionName sectionName: String?) -> String? +} + + +// MARK: - Internal + +extension Internals { + + // MARK: - FetchedResultsControllerDelegate + + @available(macOS 10.12, *) + internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResultsControllerDelegate { + + // MARK: Internal + + @nonobjc + internal var enabled = true + + @nonobjc + internal let taskGroup = DispatchGroup() + + @nonobjc + internal weak var handler: FetchedResultsControllerHandler? + + @nonobjc + internal weak var fetchedResultsController: Internals.CoreStoreFetchedResultsController? { + + didSet { + + oldValue?.delegate = nil + self.fetchedResultsController?.delegate = self + } + } + + deinit { + + self.fetchedResultsController?.delegate = nil + } + + + // MARK: NSFetchedResultsControllerDelegate + + @objc + dynamic func controllerWillChangeContent(_ controller: NSFetchedResultsController) { + + self.taskGroup.enter() + guard self.enabled else { + + return + } + + if #available(iOS 10.3, tvOS 10.3, watchOS 3.2, macOS 10.13, *) {} + else { + + self.deletedSections = [] + self.insertedSections = [] + } + + self.handler?.controllerWillChangeContent(controller) + } + + @objc + dynamic func controllerDidChangeContent(_ controller: NSFetchedResultsController) { + + defer { + + self.taskGroup.leave() + } + guard self.enabled else { + + return + } + + self.handler?.controllerDidChangeContent(controller) + } + + @objc + dynamic func controller(_ controller: NSFetchedResultsController, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) { + + guard self.enabled else { + + return + } + + if #available(iOS 10.3, tvOS 10.3, watchOS 3.2, macOS 10.13, *) { + + self.handler?.controller( + controller, + didChangeObject: anObject, + atIndexPath: indexPath, + forChangeType: type, + newIndexPath: newIndexPath + ) + return + } + + guard var actualType = NSFetchedResultsChangeType(rawValue: type.rawValue) else { + + // This fix is for a bug where iOS passes 0 for NSFetchedResultsChangeType, but this is not a valid enum case. + // Swift will then always execute the first case of the switch causing strange behaviour. + // https://forums.developer.apple.com/thread/12184#31850 + return + } + + // This whole dance is a workaround for a nasty bug introduced in XCode 7 targeted at iOS 8 devices + // http://stackoverflow.com/questions/31383760/ios-9-attempt-to-delete-and-reload-the-same-index-path/31384014#31384014 + // https://forums.developer.apple.com/message/9998#9998 + // https://forums.developer.apple.com/message/31849#31849 + + if case .update = actualType, + indexPath != nil, + newIndexPath != nil { + + actualType = .move + } + + switch actualType { + + case .update: + guard let section = indexPath?[0] else { + + return + } + if self.deletedSections.contains(section) + || self.insertedSections.contains(section) { + + return + } + + case .move: + guard let indexPath = indexPath, let newIndexPath = newIndexPath else { + + return + } + guard indexPath == newIndexPath else { + + break + } + if self.insertedSections.contains(indexPath[0]) { + + // Observers that handle the .Move change are advised to delete then reinsert the object instead of just moving. This is especially true when indexPath and newIndexPath are equal. For example, calling tableView.moveRowAtIndexPath(_:toIndexPath) when both indexPaths are the same will crash the tableView. + self.handler?.controller( + controller, + didChangeObject: anObject, + atIndexPath: indexPath, + forChangeType: .move, + newIndexPath: newIndexPath + ) + return + } + if self.deletedSections.contains(indexPath[0]) { + + self.handler?.controller( + controller, + didChangeObject: anObject, + atIndexPath: nil, + forChangeType: .insert, + newIndexPath: indexPath + ) + return + } + self.handler?.controller( + controller, + didChangeObject: anObject, + atIndexPath: indexPath, + forChangeType: .update, + newIndexPath: nil + ) + return + + default: + break + } + + self.handler?.controller( + controller, + didChangeObject: anObject, + atIndexPath: indexPath, + forChangeType: actualType, + newIndexPath: newIndexPath + ) + } + + @objc + dynamic func controller(_ controller: NSFetchedResultsController, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) { + + guard self.enabled else { + + return + } + + if #available(iOS 10.3, tvOS 10.3, watchOS 3.2, macOS 10.13, *) {} + else { + + switch type { + + case .delete: self.deletedSections.insert(sectionIndex) + case .insert: self.insertedSections.insert(sectionIndex) + default: break + } + } + + self.handler?.controller( + controller, + didChangeSection: sectionInfo, + atIndex: sectionIndex, + forChangeType: type + ) + } + + @objc + dynamic func controller(_ controller: NSFetchedResultsController, sectionIndexTitleForSectionName sectionName: String) -> String? { + + return self.handler?.controller( + controller, + sectionIndexTitleForSectionName: sectionName + ) + } + + + // MARK: Private + + @nonobjc + private var deletedSections = Set() + + @nonobjc + private var insertedSections = Set() + } +} diff --git a/Sources/MigrationManager.swift b/Sources/Internals.MigrationManager.swift similarity index 54% rename from Sources/MigrationManager.swift rename to Sources/Internals.MigrationManager.swift index e86b758..4d630e9 100644 --- a/Sources/MigrationManager.swift +++ b/Sources/Internals.MigrationManager.swift @@ -1,5 +1,5 @@ // -// MigrationManager.swift +// Internals.MigrationManager.swift // CoreStore // // Copyright © 2018 John Rommel Estropia @@ -27,39 +27,44 @@ import Foundation import CoreData -// MARK: - MigrationManager +// MARK: - Internal -internal final class MigrationManager: NSMigrationManager, ProgressReporting { - - // MARK: NSObject - - override func didChangeValue(forKey key: String) { - - super.didChangeValue(forKey: key) - - guard key == #keyPath(NSMigrationManager.migrationProgress) else { - - return +extension Internals { + + // MARK: - MigrationManager + + internal final class MigrationManager: NSMigrationManager, ProgressReporting { + + // MARK: NSObject + + override func didChangeValue(forKey key: String) { + + super.didChangeValue(forKey: key) + + guard key == #keyPath(NSMigrationManager.migrationProgress) else { + + return + } + let progress = self.progress + progress.completedUnitCount = max( + progress.completedUnitCount, + Int64(Float(progress.totalUnitCount) * self.migrationProgress) + ) } - let progress = self.progress - progress.completedUnitCount = max( - progress.completedUnitCount, - Int64(Float(progress.totalUnitCount) * self.migrationProgress) - ) - } - - - // MARK: NSMigrationManager - init(sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel, progress: Progress) { - - self.progress = progress - - super.init(sourceModel: sourceModel, destinationModel: destinationModel) - } - - // MARK: ProgressReporting - - let progress: Progress + // MARK: NSMigrationManager + + init(sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel, progress: Progress) { + + self.progress = progress + + super.init(sourceModel: sourceModel, destinationModel: destinationModel) + } + + + // MARK: ProgressReporting + + let progress: Progress + } } diff --git a/Sources/NotificationObserver.swift b/Sources/Internals.NotificationObserver.swift similarity index 62% rename from Sources/NotificationObserver.swift rename to Sources/Internals.NotificationObserver.swift index b341704..26faf20 100644 --- a/Sources/NotificationObserver.swift +++ b/Sources/Internals.NotificationObserver.swift @@ -1,5 +1,5 @@ // -// NotificationObserver.swift +// Internals.NotificationObserver.swift // CoreStore // // Copyright © 2018 John Rommel Estropia @@ -26,26 +26,31 @@ import Foundation -// MARK: - NotificationObserver +// MARK: - Internal -internal final class NotificationObserver { - - // MARK: Public - - let observer: NSObjectProtocol - - init(notificationName: Notification.Name, object: Any?, queue: OperationQueue? = nil, closure: @escaping (_ note: Notification) -> Void) { - - self.observer = NotificationCenter.default.addObserver( - forName: notificationName, - object: object, - queue: queue, - using: closure - ) - } - - deinit { - - NotificationCenter.default.removeObserver(self.observer) +extension Internals { + + // MARK: - NotificationObserver + + internal final class NotificationObserver { + + // MARK: Public + + let observer: NSObjectProtocol + + init(notificationName: Notification.Name, object: Any?, queue: OperationQueue? = nil, closure: @escaping (_ note: Notification) -> Void) { + + self.observer = NotificationCenter.default.addObserver( + forName: notificationName, + object: object, + queue: queue, + using: closure + ) + } + + deinit { + + NotificationCenter.default.removeObserver(self.observer) + } } } diff --git a/Sources/WeakObject.swift b/Sources/Internals.WeakObject.swift similarity index 77% rename from Sources/WeakObject.swift rename to Sources/Internals.WeakObject.swift index e24609a..bdc21ca 100644 --- a/Sources/WeakObject.swift +++ b/Sources/Internals.WeakObject.swift @@ -1,5 +1,5 @@ // -// WeakObject.swift +// Internals.WeakObject.swift // CoreStore // // Copyright © 2018 John Rommel Estropia @@ -23,17 +23,24 @@ // SOFTWARE. // +import Foundation -// MARK: - WeakObject -internal final class WeakObject { - - // MARK: Internal - - internal init(_ object: AnyObject) { - - self.object = object +// MARK: - Internal + +extension Internals { + + // MARK: - WeakObject + + internal final class WeakObject { + + // MARK: Internal + + internal init(_ object: AnyObject) { + + self.object = object + } + + internal private(set) weak var object: AnyObject? } - - internal private(set) weak var object: AnyObject? } diff --git a/Sources/Internals.swift b/Sources/Internals.swift new file mode 100644 index 0000000..27a1abf --- /dev/null +++ b/Sources/Internals.swift @@ -0,0 +1,125 @@ +// +// Internals.swift +// CoreStore iOS +// +// Copyright © 2018 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 + +// MARK: - Internals + +internal enum Internals { + + // MARK: Associated Objects + + @inline(__always) + /// type(of:) doesn't return the dynamic type anymore, use this to guarantee correct dispatch of class methods + internal static func dynamicObjectType(of instance: T) -> T.Type { + + return object_getClass(instance) as! T.Type + } + + // MARK: Associated Objects + + @inline(__always) + internal static func getAssociatedObjectForKey(_ key: UnsafeRawPointer, inObject object: Any) -> T? { + + switch objc_getAssociatedObject(object, key) { + + case let associatedObject as T: + return associatedObject + + case let associatedObject as Internals.WeakObject: + return associatedObject.object as? T + + default: + return nil + } + } + + @inline(__always) + internal static func setAssociatedRetainedObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: Any) { + + objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + + @inline(__always) + internal static func setAssociatedCopiedObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: Any) { + + objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_COPY_NONATOMIC) + } + + @inline(__always) + internal static func setAssociatedWeakObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: Any) { + + if let associatedObject = associatedObject { + + objc_setAssociatedObject(object, key, Internals.WeakObject(associatedObject), .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + else { + + objc_setAssociatedObject(object, key, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + } + + + // MARK: Printing Utilities + + @inline(__always) + internal static func typeName(_ value: T) -> String { + + return "'\(String(reflecting: type(of: value)))'" + } + + @inline(__always) + internal static func typeName(_ value: T.Type) -> String { + + return "'\(value)'" + } + + @inline(__always) + internal static func typeName(_ value: AnyClass) -> String { + + return "'\(value)'" + } + + @inline(__always) + internal static func typeName(_ name: String) -> String { + + return "<\(name)>" + } + + @inline(__always) + internal static func typeName(_ name: String?) -> String { + + return "<\(name ?? "unknown")>" + } + + + // MARK: Functional + + @inline(__always) + internal static func with(_ closure: () -> T) -> T { + + return closure() + } +} diff --git a/Sources/KeyPath+KeyPaths.swift b/Sources/KeyPath+KeyPaths.swift index 63e9435..50b0357 100644 --- a/Sources/KeyPath+KeyPaths.swift +++ b/Sources/KeyPath+KeyPaths.swift @@ -35,6 +35,7 @@ extension KeyPath: AnyKeyPathStringConvertible, KeyPathStringConvertible where R public var cs_keyPathString: String { +// return NSExpression(forKeyPath: self).keyPath // in case _kvcKeyPathString becomes private API return self._kvcKeyPathString! } diff --git a/Sources/KeyPathGenericBindings.swift b/Sources/KeyPathGenericBindings.swift index 29ea924..0439a34 100644 --- a/Sources/KeyPathGenericBindings.swift +++ b/Sources/KeyPathGenericBindings.swift @@ -33,7 +33,13 @@ import CoreData /** Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities. */ -public protocol AllowedObjectiveCKeyPathValue {} +public protocol AllowedObjectiveCKeyPathValue { + + /** + The destination value type + */ + associatedtype DestinationValueType +} // MARK: - AllowedOptionalObjectiveCKeyPathValue @@ -43,53 +49,125 @@ public protocol AllowedObjectiveCKeyPathValue {} */ public protocol AllowedOptionalObjectiveCKeyPathValue: AllowedObjectiveCKeyPathValue {} -extension Bool: AllowedObjectiveCKeyPathValue {} +extension Bool: AllowedObjectiveCKeyPathValue { -extension CGFloat: AllowedObjectiveCKeyPathValue {} + public typealias DestinationValueType = Bool +} -extension Data: AllowedOptionalObjectiveCKeyPathValue {} +extension CGFloat: AllowedObjectiveCKeyPathValue { -extension Date: AllowedOptionalObjectiveCKeyPathValue {} + public typealias DestinationValueType = CGFloat +} -extension Double: AllowedObjectiveCKeyPathValue {} +extension Data: AllowedOptionalObjectiveCKeyPathValue { -extension Float: AllowedObjectiveCKeyPathValue {} + public typealias DestinationValueType = Data +} -extension Int: AllowedObjectiveCKeyPathValue {} +extension Date: AllowedOptionalObjectiveCKeyPathValue { -extension Int8: AllowedObjectiveCKeyPathValue {} + public typealias DestinationValueType = Date +} -extension Int16: AllowedObjectiveCKeyPathValue {} +extension Double: AllowedObjectiveCKeyPathValue { -extension Int32: AllowedObjectiveCKeyPathValue {} + public typealias DestinationValueType = Double +} -extension Int64: AllowedObjectiveCKeyPathValue {} +extension Float: AllowedObjectiveCKeyPathValue { -extension NSData: AllowedOptionalObjectiveCKeyPathValue {} + public typealias DestinationValueType = Float +} -extension NSDate: AllowedOptionalObjectiveCKeyPathValue {} +extension Int: AllowedObjectiveCKeyPathValue { -extension NSManagedObject: AllowedOptionalObjectiveCKeyPathValue {} + public typealias DestinationValueType = Int +} -extension NSNumber: AllowedOptionalObjectiveCKeyPathValue {} +extension Int8: AllowedObjectiveCKeyPathValue { -extension NSString: AllowedOptionalObjectiveCKeyPathValue {} + public typealias DestinationValueType = Int8 +} -extension NSSet: AllowedOptionalObjectiveCKeyPathValue {} +extension Int16: AllowedObjectiveCKeyPathValue { -extension NSOrderedSet: AllowedOptionalObjectiveCKeyPathValue {} + public typealias DestinationValueType = Int16 +} -extension NSURL: AllowedOptionalObjectiveCKeyPathValue {} +extension Int32: AllowedObjectiveCKeyPathValue { -extension NSUUID: AllowedOptionalObjectiveCKeyPathValue {} + public typealias DestinationValueType = Int32 +} -extension String: AllowedOptionalObjectiveCKeyPathValue {} +extension Int64: AllowedObjectiveCKeyPathValue { -extension URL: AllowedOptionalObjectiveCKeyPathValue {} + public typealias DestinationValueType = Int64 +} -extension UUID: AllowedOptionalObjectiveCKeyPathValue {} +extension NSData: AllowedOptionalObjectiveCKeyPathValue { -extension Optional: AllowedObjectiveCKeyPathValue where Wrapped: AllowedOptionalObjectiveCKeyPathValue {} + public typealias DestinationValueType = Self +} + +extension NSDate: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Self +} + +extension NSManagedObject: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Self +} + +extension NSNumber: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Self +} + +extension NSString: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Self +} + +extension NSSet: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Self +} + +extension NSOrderedSet: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Self +} + +extension NSURL: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Self +} + +extension NSUUID: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Self +} + +extension String: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = String +} + +extension URL: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = URL +} + +extension UUID: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = UUID +} + +extension Optional: AllowedObjectiveCKeyPathValue where Wrapped: AllowedOptionalObjectiveCKeyPathValue { + + public typealias DestinationValueType = Wrapped.DestinationValueType +} // MARK: - AllowedObjectiveCAttributeKeyPathValue @@ -97,49 +175,118 @@ extension Optional: AllowedObjectiveCKeyPathValue where Wrapped: AllowedOptional /** Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities. */ -public protocol AllowedObjectiveCAttributeKeyPathValue: AllowedObjectiveCKeyPathValue {} +public protocol AllowedObjectiveCAttributeKeyPathValue: AllowedObjectiveCKeyPathValue { -extension Bool: AllowedObjectiveCAttributeKeyPathValue {} + /** + The attribute value type + */ + associatedtype ReturnValueType +} -extension CGFloat: AllowedObjectiveCAttributeKeyPathValue {} +extension Bool: AllowedObjectiveCAttributeKeyPathValue { -extension Data: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = Bool +} -extension Date: AllowedObjectiveCAttributeKeyPathValue {} +extension CGFloat: AllowedObjectiveCAttributeKeyPathValue { -extension Double: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = CGFloat +} -extension Float: AllowedObjectiveCAttributeKeyPathValue {} +extension Data: AllowedObjectiveCAttributeKeyPathValue { -extension Int: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = Data +} -extension Int8: AllowedObjectiveCAttributeKeyPathValue {} +extension Date: AllowedObjectiveCAttributeKeyPathValue { -extension Int16: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = Date +} -extension Int32: AllowedObjectiveCAttributeKeyPathValue {} +extension Double: AllowedObjectiveCAttributeKeyPathValue { -extension Int64: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = Double +} -extension NSData: AllowedObjectiveCAttributeKeyPathValue {} +extension Float: AllowedObjectiveCAttributeKeyPathValue { -extension NSDate: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = Float +} -extension NSNumber: AllowedObjectiveCAttributeKeyPathValue {} +extension Int: AllowedObjectiveCAttributeKeyPathValue { -extension NSString: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = Int +} -extension NSURL: AllowedObjectiveCAttributeKeyPathValue {} +extension Int8: AllowedObjectiveCAttributeKeyPathValue { -extension NSUUID: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = Int8 +} -extension String: AllowedObjectiveCAttributeKeyPathValue {} +extension Int16: AllowedObjectiveCAttributeKeyPathValue { -extension URL: AllowedObjectiveCAttributeKeyPathValue {} + public typealias ReturnValueType = Int16 +} -extension UUID: AllowedObjectiveCAttributeKeyPathValue {} +extension Int32: AllowedObjectiveCAttributeKeyPathValue { -extension Optional: AllowedObjectiveCAttributeKeyPathValue where Wrapped: AllowedObjectiveCAttributeKeyPathValue, Wrapped: AllowedOptionalObjectiveCKeyPathValue {} + public typealias ReturnValueType = Int32 +} + +extension Int64: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = Int64 +} + +extension NSData: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = Self +} + +extension NSDate: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = Self +} + +extension NSNumber: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = Self +} + +extension NSString: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = Self +} + +extension NSURL: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = Self +} + +extension NSUUID: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = Self +} + +extension String: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = String +} + +extension URL: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = URL +} + +extension UUID: AllowedObjectiveCAttributeKeyPathValue { + + public typealias ReturnValueType = UUID +} + +extension Optional: AllowedObjectiveCAttributeKeyPathValue where Wrapped: AllowedObjectiveCAttributeKeyPathValue, Wrapped: AllowedOptionalObjectiveCKeyPathValue { + + public typealias ReturnValueType = Optional +} // MARK: - AllowedObjectiveCRelationshipKeyPathValue diff --git a/Sources/ListMonitor.swift b/Sources/ListMonitor.swift index 30f134b..fb8a382 100644 --- a/Sources/ListMonitor.swift +++ b/Sources/ListMonitor.swift @@ -84,9 +84,9 @@ public final class ListMonitor: Hashable { */ public subscript(index: Int) -> ObjectType { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) if self.isSectioned { @@ -155,9 +155,9 @@ public final class ListMonitor: Hashable { */ public subscript(indexPath: IndexPath) -> ObjectType { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return ObjectType.cs_fromRaw(object: self.fetchedResultsController.object(at: indexPath)) } @@ -214,9 +214,9 @@ public final class ListMonitor: Hashable { */ public func numberOfSections() -> Int { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sections?.count ?? 0 } @@ -228,9 +228,9 @@ public final class ListMonitor: Hashable { */ public func numberOfObjects() -> Int { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return (self.fetchedResultsController.fetchedObjects as NSArray?)?.count ?? 0 } @@ -265,9 +265,9 @@ public final class ListMonitor: Hashable { */ public func sectionInfo(at section: Int) -> NSFetchedResultsSectionInfo { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sections![section] } @@ -280,9 +280,9 @@ public final class ListMonitor: Hashable { */ public func sectionInfo(safelyAt section: Int) -> NSFetchedResultsSectionInfo? { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) guard section >= 0 else { @@ -302,9 +302,9 @@ public final class ListMonitor: Hashable { */ public func sections() -> [NSFetchedResultsSectionInfo] { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sections ?? [] } @@ -318,9 +318,9 @@ public final class ListMonitor: Hashable { */ public func targetSection(forSectionIndexTitle sectionIndexTitle: String, at sectionIndex: Int) -> Int { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.section(forSectionIndexTitle: sectionIndexTitle, at: sectionIndex) } @@ -332,9 +332,9 @@ public final class ListMonitor: Hashable { */ public func sectionIndexTitles() -> [String] { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sectionIndexTitles } @@ -347,9 +347,9 @@ public final class ListMonitor: Hashable { */ public func index(of object: ObjectType) -> Int? { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) if self.isSectioned { @@ -366,9 +366,9 @@ public final class ListMonitor: Hashable { */ public func indexPath(of object: ObjectType) -> IndexPath? { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.indexPath(forObject: object.cs_toRaw()) } @@ -628,7 +628,7 @@ public final class ListMonitor: Hashable { // MARK: Internal - internal convenience init(dataStack: DataStack, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void) { + internal convenience init(dataStack: DataStack, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void) { self.init( context: dataStack.mainContext, @@ -640,7 +640,7 @@ public final class ListMonitor: Hashable { ) } - internal convenience init(dataStack: DataStack, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void, createAsynchronously: @escaping (ListMonitor) -> Void) { + internal convenience init(dataStack: DataStack, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void, createAsynchronously: @escaping (ListMonitor) -> Void) { self.init( context: dataStack.mainContext, @@ -652,7 +652,7 @@ public final class ListMonitor: Hashable { ) } - internal convenience init(unsafeTransaction: UnsafeDataTransaction, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void) { + internal convenience init(unsafeTransaction: UnsafeDataTransaction, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void) { self.init( context: unsafeTransaction.context, @@ -664,7 +664,7 @@ public final class ListMonitor: Hashable { ) } - internal convenience init(unsafeTransaction: UnsafeDataTransaction, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void, createAsynchronously: @escaping (ListMonitor) -> Void) { + internal convenience init(unsafeTransaction: UnsafeDataTransaction, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void, createAsynchronously: @escaping (ListMonitor) -> Void) { self.init( context: unsafeTransaction.context, @@ -678,8 +678,8 @@ public final class ListMonitor: Hashable { internal func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor) -> Void) { - cs_setAssociatedRetainedObject( - NotificationObserver( + Internals.setAssociatedRetainedObject( + Internals.NotificationObserver( notificationName: name, object: self, closure: { [weak self] (note) -> Void in @@ -698,8 +698,8 @@ public final class ListMonitor: Hashable { internal func registerObjectNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor, _ object: ObjectType, _ indexPath: IndexPath?, _ newIndexPath: IndexPath?) -> Void) { - cs_setAssociatedRetainedObject( - NotificationObserver( + Internals.setAssociatedRetainedObject( + Internals.NotificationObserver( notificationName: name, object: self, closure: { [weak self] (note) -> Void in @@ -725,8 +725,8 @@ public final class ListMonitor: Hashable { internal func registerSectionNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor, _ sectionInfo: NSFetchedResultsSectionInfo, _ sectionIndex: Int) -> Void) { - cs_setAssociatedRetainedObject( - NotificationObserver( + Internals.setAssociatedRetainedObject( + Internals.NotificationObserver( notificationName: name, object: self, closure: { [weak self] (note) -> Void in @@ -748,9 +748,9 @@ public final class ListMonitor: Hashable { internal func registerObserver(_ observer: U, willChange: @escaping (_ observer: U, _ monitor: ListMonitor) -> Void, didChange: @escaping (_ observer: U, _ monitor: ListMonitor) -> Void, willRefetch: @escaping (_ observer: U, _ monitor: ListMonitor) -> Void, didRefetch: @escaping (_ observer: U, _ monitor: ListMonitor) -> Void) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread." + "Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread." ) self.registerChangeNotification( &self.willChangeListKey, @@ -808,9 +808,9 @@ public final class ListMonitor: Hashable { internal func registerObserver(_ observer: U, didInsertObject: @escaping (_ observer: U, _ monitor: ListMonitor, _ object: ObjectType, _ toIndexPath: IndexPath) -> Void, didDeleteObject: @escaping (_ observer: U, _ monitor: ListMonitor, _ object: ObjectType, _ fromIndexPath: IndexPath) -> Void, didUpdateObject: @escaping (_ observer: U, _ monitor: ListMonitor, _ object: ObjectType, _ atIndexPath: IndexPath) -> Void, didMoveObject: @escaping (_ observer: U, _ monitor: ListMonitor, _ object: ObjectType, _ fromIndexPath: IndexPath, _ toIndexPath: IndexPath) -> Void) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread." + "Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread." ) self.registerObjectNotification( @@ -869,9 +869,9 @@ public final class ListMonitor: Hashable { internal func registerObserver(_ observer: U, didInsertSection: @escaping (_ observer: U, _ monitor: ListMonitor, _ sectionInfo: NSFetchedResultsSectionInfo, _ toIndex: Int) -> Void, didDeleteSection: @escaping (_ observer: U, _ monitor: ListMonitor, _ sectionInfo: NSFetchedResultsSectionInfo, _ fromIndex: Int) -> Void) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread." + "Attempted to add an observer of type \(Internals.typeName(observer)) outside the main thread." ) self.registerSectionNotification( @@ -904,30 +904,30 @@ public final class ListMonitor: Hashable { internal func unregisterObserver(_ observer: AnyObject) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread." + "Attempted to remove an observer of type \(Internals.typeName(observer)) outside the main thread." ) let nilValue: AnyObject? = nil - cs_setAssociatedRetainedObject(nilValue, forKey: &self.willChangeListKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didChangeListKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.willRefetchListKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didRefetchListKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.willChangeListKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didChangeListKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.willRefetchListKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didRefetchListKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didInsertObjectKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didMoveObjectKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didInsertObjectKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didMoveObjectKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didInsertSectionKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteSectionKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didInsertSectionKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteSectionKey, inObject: observer) } - internal func refetch(_ applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void) { + internal func refetch(_ applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to refetch a \(cs_typeName(self)) outside the main thread." + "Attempted to refetch a \(Internals.typeName(self)) outside the main thread." ) if !self.isPendingRefetch { @@ -1006,7 +1006,7 @@ public final class ListMonitor: Hashable { // MARK: Private - fileprivate var fetchedResultsController: CoreStoreFetchedResultsController + fileprivate var fetchedResultsController: Internals.CoreStoreFetchedResultsController fileprivate let taskGroup = DispatchGroup() fileprivate let sectionIndexTransformer: (_ sectionName: KeyPathString?) -> String? @@ -1025,11 +1025,11 @@ public final class ListMonitor: Hashable { private var didInsertSectionKey: Void? private var didDeleteSectionKey: Void? - private var fetchedResultsControllerDelegate: FetchedResultsControllerDelegate - private var observerForWillChangePersistentStore: NotificationObserver! - private var observerForDidChangePersistentStore: NotificationObserver! + private var fetchedResultsControllerDelegate: Internals.FetchedResultsControllerDelegate + private var observerForWillChangePersistentStore: Internals.NotificationObserver! + private var observerForDidChangePersistentStore: Internals.NotificationObserver! private let transactionQueue: DispatchQueue - private var applyFetchClauses: (_ fetchRequest: CoreStoreFetchRequest) -> Void + private var applyFetchClauses: (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void private var isPersistentStoreChanging: Bool = false { @@ -1052,16 +1052,16 @@ public final class ListMonitor: Hashable { } } - private static func recreateFetchedResultsController(context: NSManagedObjectContext, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void) -> (controller: CoreStoreFetchedResultsController, delegate: FetchedResultsControllerDelegate) { + private static func recreateFetchedResultsController(context: NSManagedObjectContext, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void) -> (controller: Internals.CoreStoreFetchedResultsController, delegate: Internals.FetchedResultsControllerDelegate) { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectResultType fetchRequest.fetchBatchSize = 20 fetchRequest.includesPendingChanges = false fetchRequest.shouldRefreshRefetchedObjects = true - let fetchedResultsController = CoreStoreFetchedResultsController( + let fetchedResultsController = Internals.CoreStoreFetchedResultsController( context: context, fetchRequest: fetchRequest, from: from, @@ -1069,7 +1069,7 @@ public final class ListMonitor: Hashable { applyFetchClauses: applyFetchClauses ) - let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate() + let fetchedResultsControllerDelegate = Internals.FetchedResultsControllerDelegate() fetchedResultsControllerDelegate.fetchedResultsController = fetchedResultsController return (fetchedResultsController, fetchedResultsControllerDelegate) @@ -1078,7 +1078,7 @@ public final class ListMonitor: Hashable { private let from: From private let sectionBy: SectionBy? - private init(context: NSManagedObjectContext, transactionQueue: DispatchQueue, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: CoreStoreFetchRequest) -> Void, createAsynchronously: ((ListMonitor) -> Void)?) { + private init(context: NSManagedObjectContext, transactionQueue: DispatchQueue, from: From, sectionBy: SectionBy?, applyFetchClauses: @escaping (_ fetchRequest: Internals.CoreStoreFetchRequest) -> Void, createAsynchronously: ((ListMonitor) -> Void)?) { self.isSectioned = (sectionBy != nil) self.from = from @@ -1107,7 +1107,7 @@ public final class ListMonitor: Hashable { return } - self.observerForWillChangePersistentStore = NotificationObserver( + self.observerForWillChangePersistentStore = Internals.NotificationObserver( notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresWillChange, object: coordinator, queue: OperationQueue.main, @@ -1129,7 +1129,7 @@ public final class ListMonitor: Hashable { } ) - self.observerForDidChangePersistentStore = NotificationObserver( + self.observerForDidChangePersistentStore = Internals.NotificationObserver( notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresDidChange, object: coordinator, queue: OperationQueue.main, @@ -1239,9 +1239,9 @@ extension ListMonitor where ListMonitor.ObjectType: NSManagedObject { */ public func objectsInAllSections() -> [ObjectType] { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return (self.fetchedResultsController.dynamicCast() as NSFetchedResultsController).fetchedObjects ?? [] } @@ -1297,9 +1297,9 @@ extension ListMonitor where ListMonitor.ObjectType: CoreStoreObject { */ public func objectsInAllSections() -> [ObjectType] { - CoreStore.assert( + Internals.assert( !self.isPendingRefetch || Thread.isMainThread, - "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(Internals.typeName(self)) outside the main thread while a refetch is in progress." ) return (self.fetchedResultsController.fetchedObjects ?? []) .map(ObjectType.cs_fromRaw) diff --git a/Sources/MigrationChain.swift b/Sources/MigrationChain.swift index 0f0acc9..5301b70 100644 --- a/Sources/MigrationChain.swift +++ b/Sources/MigrationChain.swift @@ -89,7 +89,7 @@ public struct MigrationChain: ExpressibleByNilLiteral, ExpressibleByStringLitera */ public init(_ elements: T) where T.Iterator.Element == String { - CoreStore.assert(Set(elements).count == Array(elements).count, "\(cs_typeName(MigrationChain.self))'s migration chain could not be created due to duplicate version strings.") + Internals.assert(Set(elements).count == Array(elements).count, "\(Internals.typeName(MigrationChain.self))'s migration chain could not be created due to duplicate version strings.") var lastVersion: String? var versionTree = [String: String]() @@ -125,7 +125,7 @@ public struct MigrationChain: ExpressibleByNilLiteral, ExpressibleByStringLitera return } - CoreStore.assert(false, "\(cs_typeName(MigrationChain.self))'s migration chain could not be created due to ambiguous version paths.") + Internals.assert(false, "\(Internals.typeName(MigrationChain.self))'s migration chain could not be created due to ambiguous version paths.") isValid = false } @@ -143,7 +143,7 @@ public struct MigrationChain: ExpressibleByNilLiteral, ExpressibleByStringLitera if checklist.contains(nextVersion) { - CoreStore.assert(false, "\(cs_typeName(MigrationChain.self))'s migration chain could not be created due to looping version paths.") + Internals.assert(false, "\(Internals.typeName(MigrationChain.self))'s migration chain could not be created due to looping version paths.") return true } diff --git a/Sources/NSFetchedResultsController+Convenience.swift b/Sources/NSFetchedResultsController+Convenience.swift index 227fac7..7c96fd4 100644 --- a/Sources/NSFetchedResultsController+Convenience.swift +++ b/Sources/NSFetchedResultsController+Convenience.swift @@ -44,7 +44,7 @@ extension DataStack { @nonobjc public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { - return createFRC( + return Internals.createFRC( fromContext: self.mainContext, from: from, sectionBy: sectionBy, @@ -64,7 +64,7 @@ extension DataStack { @nonobjc public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { - return createFRC( + return Internals.createFRC( fromContext: self.mainContext, from: from, sectionBy: sectionBy, @@ -83,7 +83,7 @@ extension DataStack { @nonobjc public func createFetchedResultsController(_ from: From, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { - return createFRC( + return Internals.createFRC( fromContext: self.mainContext, from: from, sectionBy: nil, @@ -102,7 +102,7 @@ extension DataStack { @nonobjc public func createFetchedResultsController(forDataStack dataStack: DataStack, _ from: From, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { - return createFRC( + return Internals.createFRC( fromContext: self.mainContext, from: from, sectionBy: nil, @@ -129,7 +129,7 @@ extension UnsafeDataTransaction { @nonobjc public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { - return createFRC( + return Internals.createFRC( fromContext: self.context, from: from, sectionBy: sectionBy, @@ -149,7 +149,7 @@ extension UnsafeDataTransaction { @nonobjc public func createFetchedResultsController(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { - return createFRC( + return Internals.createFRC( fromContext: self.context, from: from, sectionBy: sectionBy, @@ -168,7 +168,7 @@ extension UnsafeDataTransaction { @nonobjc public func createFetchedResultsController(_ from: From, _ fetchClauses: FetchClause...) -> NSFetchedResultsController { - return createFRC( + return Internals.createFRC( fromContext: self.context, from: from, sectionBy: nil, @@ -187,7 +187,7 @@ extension UnsafeDataTransaction { @nonobjc public func createFetchedResultsController(_ from: From, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController { - return createFRC( + return Internals.createFRC( fromContext: self.context, from: from, sectionBy: nil, @@ -198,25 +198,30 @@ extension UnsafeDataTransaction { -// MARK: - Private +// MARK: - Internals -@available(macOS 10.12, *) -fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: From, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController { - - let controller = CoreStoreFetchedResultsController( - context: context, - fetchRequest: CoreStoreFetchRequest(), - from: from, - sectionBy: sectionBy, - applyFetchClauses: { (fetchRequest) in - - fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - CoreStore.assert( - fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(NSFetchedResultsController.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor." - ) - } - ) - return controller.dynamicCast() +extension Internals { + + // MARK: FilePrivate + + @available(macOS 10.12, *) + fileprivate static func createFRC(fromContext context: NSManagedObjectContext, from: From, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController { + + let controller = Internals.CoreStoreFetchedResultsController( + context: context, + fetchRequest: Internals.CoreStoreFetchRequest(), + from: from, + sectionBy: sectionBy, + applyFetchClauses: { (fetchRequest) in + + fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } + + Internals.assert( + fetchRequest.sortDescriptors?.isEmpty == false, + "An \(Internals.typeName(NSFetchedResultsController.self)) requires a sort information. Specify from a \(Internals.typeName(OrderBy.self)) clause or any custom \(Internals.typeName(FetchClause.self)) that provides a sort descriptor." + ) + } + ) + return controller.dynamicCast() + } } diff --git a/Sources/NSManagedObject+DynamicModel.swift b/Sources/NSManagedObject+DynamicModel.swift index 2aa05fe..1ef4525 100644 --- a/Sources/NSManagedObject+DynamicModel.swift +++ b/Sources/NSManagedObject+DynamicModel.swift @@ -36,14 +36,14 @@ extension NSManagedObject { get { - return cs_getAssociatedObjectForKey( + return Internals.getAssociatedObjectForKey( &PropertyKeys.coreStoreObject, inObject: self ) } set { - cs_setAssociatedWeakObject( + Internals.setAssociatedWeakObject( newValue, forKey: &PropertyKeys.coreStoreObject, inObject: self diff --git a/Sources/NSManagedObjectContext+CoreStore.swift b/Sources/NSManagedObjectContext+CoreStore.swift index dbab567..8efda4c 100644 --- a/Sources/NSManagedObjectContext+CoreStore.swift +++ b/Sources/NSManagedObjectContext+CoreStore.swift @@ -38,7 +38,7 @@ extension NSManagedObjectContext { get { - let number: NSNumber? = cs_getAssociatedObjectForKey( + let number: NSNumber? = Internals.getAssociatedObjectForKey( &PropertyKeys.shouldCascadeSavesToParent, inObject: self ) @@ -46,7 +46,7 @@ extension NSManagedObjectContext { } set { - cs_setAssociatedCopiedObject( + Internals.setAssociatedCopiedObject( NSNumber(value: newValue), forKey: &PropertyKeys.shouldCascadeSavesToParent, inObject: self @@ -58,7 +58,7 @@ extension NSManagedObjectContext { internal func setupForCoreStoreWithContextName(_ contextName: String) { self.name = contextName - self.observerForWillSaveNotification = NotificationObserver( + self.observerForWillSaveNotification = Internals.NotificationObserver( notificationName: NSNotification.Name.NSManagedObjectContextWillSave, object: self, closure: { (note) -> Void in @@ -77,7 +77,7 @@ extension NSManagedObjectContext { } catch { - CoreStore.log( + Internals.log( CoreStoreError(error), "Failed to obtain permanent ID(s) for \(numberOfInsertedObjects) inserted object(s)." ) @@ -96,18 +96,18 @@ extension NSManagedObjectContext { } @nonobjc - private var observerForWillSaveNotification: NotificationObserver? { + private var observerForWillSaveNotification: Internals.NotificationObserver? { get { - return cs_getAssociatedObjectForKey( + return Internals.getAssociatedObjectForKey( &PropertyKeys.observerForWillSaveNotification, inObject: self ) } set { - cs_setAssociatedRetainedObject( + Internals.setAssociatedRetainedObject( newValue, forKey: &PropertyKeys.observerForWillSaveNotification, inObject: self diff --git a/Sources/NSManagedObjectContext+ObjectiveC.swift b/Sources/NSManagedObjectContext+ObjectiveC.swift index dbd1c33..76c3e9d 100644 --- a/Sources/NSManagedObjectContext+ObjectiveC.swift +++ b/Sources/NSManagedObjectContext+ObjectiveC.swift @@ -36,7 +36,7 @@ extension NSManagedObjectContext { @nonobjc internal func fetchOne(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> NSManagedObject? { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 1 @@ -49,7 +49,7 @@ extension NSManagedObjectContext { @nonobjc internal func fetchAll(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> [T] { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -62,7 +62,7 @@ extension NSManagedObjectContext { @nonobjc internal func fetchCount(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> Int { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.resultType = .countResultType @@ -74,7 +74,7 @@ extension NSManagedObjectContext { @nonobjc internal func fetchObjectID(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> NSManagedObjectID? { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 1 @@ -87,7 +87,7 @@ extension NSManagedObjectContext { @nonobjc internal func fetchObjectIDs(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> [NSManagedObjectID] { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -100,7 +100,7 @@ extension NSManagedObjectContext { @nonobjc internal func deleteAll(_ from: CSFrom, _ deleteClauses: [CSDeleteClause]) throws -> Int { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -115,7 +115,7 @@ extension NSManagedObjectContext { @nonobjc internal func queryValue(_ from: CSFrom, _ selectClause: CSSelect, _ queryClauses: [CSQueryClause]) throws -> Any? { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -129,7 +129,7 @@ extension NSManagedObjectContext { @nonobjc internal func queryAttributes(_ from: CSFrom, _ selectClause: CSSelect, _ queryClauses: [CSQueryClause]) throws -> [[String: Any]] { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 diff --git a/Sources/NSManagedObjectContext+Querying.swift b/Sources/NSManagedObjectContext+Querying.swift index b7d655c..56d098f 100644 --- a/Sources/NSManagedObjectContext+Querying.swift +++ b/Sources/NSManagedObjectContext+Querying.swift @@ -48,7 +48,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } catch { - CoreStore.log( + Internals.log( CoreStoreError(error), "Failed to obtain permanent ID for object." ) @@ -62,13 +62,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { return object } - return cs_dynamicType(of: object).cs_fromRaw(object: existingRawObject) + return Internals.dynamicObjectType(of: object).cs_fromRaw(object: existingRawObject) } catch { - CoreStore.log( + Internals.log( CoreStoreError(error), - "Failed to load existing \(cs_typeName(object)) in context." + "Failed to load existing \(Internals.typeName(object)) in context." ) return nil } @@ -109,7 +109,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 1 @@ -134,7 +134,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -160,7 +160,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.resultType = .countResultType @@ -184,7 +184,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 1 @@ -209,7 +209,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -226,7 +226,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - internal func fetchObjectIDs(_ fetchRequest: CoreStoreFetchRequest) throws -> [NSManagedObjectID] { + internal func fetchObjectIDs(_ fetchRequest: Internals.CoreStoreFetchRequest) throws -> [NSManagedObjectID] { var fetchResults: [NSManagedObjectID]? var fetchError: Error? @@ -246,7 +246,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { return fetchResults } let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing fetch request." ) @@ -265,7 +265,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> U? { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -291,7 +291,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> [[String: Any]] { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -322,7 +322,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc internal func deleteAll(_ from: From, _ deleteClauses: [FetchClause]) throws -> Int { - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 @@ -343,7 +343,7 @@ extension NSManagedObjectContext { // MARK: Fetching @nonobjc - internal func fetchOne(_ fetchRequest: CoreStoreFetchRequest) throws -> D? { + internal func fetchOne(_ fetchRequest: Internals.CoreStoreFetchRequest) throws -> D? { var fetchResults: [D]? var fetchError: Error? @@ -363,7 +363,7 @@ extension NSManagedObjectContext { return fetchResults.first } let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing fetch request." ) @@ -371,7 +371,7 @@ extension NSManagedObjectContext { } @nonobjc - internal func fetchAll(_ fetchRequest: CoreStoreFetchRequest) throws -> [D] { + internal func fetchAll(_ fetchRequest: Internals.CoreStoreFetchRequest) throws -> [D] { var fetchResults: [D]? var fetchError: Error? @@ -391,7 +391,7 @@ extension NSManagedObjectContext { return fetchResults } let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing fetch request." ) @@ -399,7 +399,7 @@ extension NSManagedObjectContext { } @nonobjc - internal func fetchCount(_ fetchRequest: CoreStoreFetchRequest) throws -> Int { + internal func fetchCount(_ fetchRequest: Internals.CoreStoreFetchRequest) throws -> Int { var count = 0 var countError: Error? @@ -417,7 +417,7 @@ extension NSManagedObjectContext { if count == NSNotFound { let coreStoreError = CoreStoreError(countError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing count request." ) @@ -427,7 +427,7 @@ extension NSManagedObjectContext { } @nonobjc - internal func fetchObjectID(_ fetchRequest: CoreStoreFetchRequest) throws -> NSManagedObjectID? { + internal func fetchObjectID(_ fetchRequest: Internals.CoreStoreFetchRequest) throws -> NSManagedObjectID? { var fetchResults: [NSManagedObjectID]? var fetchError: Error? @@ -447,7 +447,7 @@ extension NSManagedObjectContext { return fetchResults.first } let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing fetch request." ) @@ -458,7 +458,7 @@ extension NSManagedObjectContext { // MARK: Querying @nonobjc - internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: CoreStoreFetchRequest) throws -> U? { + internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: Internals.CoreStoreFetchRequest) throws -> U? { var fetchResults: [Any]? var fetchError: Error? @@ -483,7 +483,7 @@ extension NSManagedObjectContext { return nil } let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing fetch request." ) @@ -491,7 +491,7 @@ extension NSManagedObjectContext { } @nonobjc - internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: CoreStoreFetchRequest) throws -> Any? { + internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: Internals.CoreStoreFetchRequest) throws -> Any? { var fetchResults: [Any]? var fetchError: Error? @@ -516,7 +516,7 @@ extension NSManagedObjectContext { return nil } let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing fetch request." ) @@ -524,7 +524,7 @@ extension NSManagedObjectContext { } @nonobjc - internal func queryAttributes(_ fetchRequest: CoreStoreFetchRequest) throws -> [[String: Any]] { + internal func queryAttributes(_ fetchRequest: Internals.CoreStoreFetchRequest) throws -> [[String: Any]] { var fetchResults: [Any]? var fetchError: Error? @@ -544,7 +544,7 @@ extension NSManagedObjectContext { return NSDictionary.cs_fromQueryResultsNativeType(fetchResults) } let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing fetch request." ) @@ -555,7 +555,7 @@ extension NSManagedObjectContext { // MARK: Deleting @nonobjc - internal func deleteAll(_ fetchRequest: CoreStoreFetchRequest) throws -> Int { + internal func deleteAll(_ fetchRequest: Internals.CoreStoreFetchRequest) throws -> Int { var numberOfDeletedObjects: Int? var fetchError: Error? @@ -583,7 +583,7 @@ extension NSManagedObjectContext { return numberOfDeletedObjects } let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( + Internals.log( coreStoreError, "Failed executing delete request." ) diff --git a/Sources/NSManagedObjectContext+Setup.swift b/Sources/NSManagedObjectContext+Setup.swift index 130ca0e..cb82bce 100644 --- a/Sources/NSManagedObjectContext+Setup.swift +++ b/Sources/NSManagedObjectContext+Setup.swift @@ -43,7 +43,7 @@ extension NSManagedObjectContext { return parentContext.parentStack } - return cs_getAssociatedObjectForKey(&PropertyKeys.parentStack, inObject: self) + return Internals.getAssociatedObjectForKey(&PropertyKeys.parentStack, inObject: self) } set { @@ -52,7 +52,7 @@ extension NSManagedObjectContext { return } - cs_setAssociatedWeakObject( + Internals.setAssociatedWeakObject( newValue, forKey: &PropertyKeys.parentStack, inObject: self @@ -71,7 +71,7 @@ extension NSManagedObjectContext { #if os(iOS) || os(macOS) - context.observerForDidImportUbiquitousContentChangesNotification = NotificationObserver( + context.observerForDidImportUbiquitousContentChangesNotification = Internals.NotificationObserver( notificationName: NSNotification.Name("com.apple.coredata.ubiquity.importer.didfinishimport"), // NSNotification.Name.NSPersistentStoreDidImportUbiquitousContentChanges (used string literals to silence deprecation warning) object: coordinator, closure: { [weak context] (note) -> Void in @@ -103,7 +103,7 @@ extension NSManagedObjectContext { context.mergePolicy = NSRollbackMergePolicy context.undoManager = nil context.setupForCoreStoreWithContextName("com.corestore.maincontext") - context.observerForDidSaveNotification = NotificationObserver( + context.observerForDidSaveNotification = Internals.NotificationObserver( notificationName: NSNotification.Name.NSManagedObjectContextDidSave, object: rootContext, closure: { [weak context] (note) -> Void in @@ -148,18 +148,18 @@ extension NSManagedObjectContext { } @nonobjc - private var observerForDidSaveNotification: NotificationObserver? { + private var observerForDidSaveNotification: Internals.NotificationObserver? { get { - return cs_getAssociatedObjectForKey( + return Internals.getAssociatedObjectForKey( &PropertyKeys.observerForDidSaveNotification, inObject: self ) } set { - cs_setAssociatedRetainedObject( + Internals.setAssociatedRetainedObject( newValue, forKey: &PropertyKeys.observerForDidSaveNotification, inObject: self @@ -168,18 +168,18 @@ extension NSManagedObjectContext { } @nonobjc - private var observerForDidImportUbiquitousContentChangesNotification: NotificationObserver? { + private var observerForDidImportUbiquitousContentChangesNotification: Internals.NotificationObserver? { get { - return cs_getAssociatedObjectForKey( + return Internals.getAssociatedObjectForKey( &PropertyKeys.observerForDidImportUbiquitousContentChangesNotification, inObject: self ) } set { - cs_setAssociatedRetainedObject( + Internals.setAssociatedRetainedObject( newValue, forKey: &PropertyKeys.observerForDidImportUbiquitousContentChangesNotification, inObject: self diff --git a/Sources/NSManagedObjectContext+Transaction.swift b/Sources/NSManagedObjectContext+Transaction.swift index a1a80ff..4c5ad1c 100644 --- a/Sources/NSManagedObjectContext+Transaction.swift +++ b/Sources/NSManagedObjectContext+Transaction.swift @@ -38,14 +38,14 @@ extension NSManagedObjectContext { get { - return cs_getAssociatedObjectForKey( + return Internals.getAssociatedObjectForKey( &PropertyKeys.parentTransaction, inObject: self ) } set { - cs_setAssociatedWeakObject( + Internals.setAssociatedWeakObject( newValue, forKey: &PropertyKeys.parentTransaction, inObject: self @@ -58,7 +58,7 @@ extension NSManagedObjectContext { get { - let value: NSNumber? = cs_getAssociatedObjectForKey( + let value: NSNumber? = Internals.getAssociatedObjectForKey( &PropertyKeys.isSavingSynchronously, inObject: self ) @@ -66,7 +66,7 @@ extension NSManagedObjectContext { } set { - cs_setAssociatedWeakObject( + Internals.setAssociatedWeakObject( newValue.flatMap { NSNumber(value: $0) }, forKey: &PropertyKeys.isSavingSynchronously, inObject: self @@ -79,7 +79,7 @@ extension NSManagedObjectContext { get { - let value: NSNumber? = cs_getAssociatedObjectForKey( + let value: NSNumber? = Internals.getAssociatedObjectForKey( &PropertyKeys.isTransactionContext, inObject: self ) @@ -87,7 +87,7 @@ extension NSManagedObjectContext { } set { - cs_setAssociatedCopiedObject( + Internals.setAssociatedCopiedObject( NSNumber(value: newValue), forKey: &PropertyKeys.isTransactionContext, inObject: self @@ -100,7 +100,7 @@ extension NSManagedObjectContext { get { - let value: NSNumber? = cs_getAssociatedObjectForKey( + let value: NSNumber? = Internals.getAssociatedObjectForKey( &PropertyKeys.isDataStackContext, inObject: self ) @@ -108,7 +108,7 @@ extension NSManagedObjectContext { } set { - cs_setAssociatedCopiedObject( + Internals.setAssociatedCopiedObject( NSNumber(value: newValue), forKey: &PropertyKeys.isDataStackContext, inObject: self @@ -158,9 +158,9 @@ extension NSManagedObjectContext { catch { let saveError = CoreStoreError(error) - CoreStore.log( + Internals.log( saveError, - "Failed to save \(cs_typeName(NSManagedObjectContext.self))." + "Failed to save \(Internals.typeName(NSManagedObjectContext.self))." ) result = (true, saveError) return @@ -200,9 +200,9 @@ extension NSManagedObjectContext { catch { let saveError = CoreStoreError(error) - CoreStore.log( + Internals.log( saveError, - "Failed to save \(cs_typeName(NSManagedObjectContext.self))." + "Failed to save \(Internals.typeName(NSManagedObjectContext.self))." ) DispatchQueue.main.async { diff --git a/Sources/NSPersistentStore+Setup.swift b/Sources/NSPersistentStore+Setup.swift index de3d5ee..a8c7483 100644 --- a/Sources/NSPersistentStore+Setup.swift +++ b/Sources/NSPersistentStore+Setup.swift @@ -38,7 +38,7 @@ extension NSPersistentStore { get { - let wrapper: StorageObject? = cs_getAssociatedObjectForKey( + let wrapper: StorageObject? = Internals.getAssociatedObjectForKey( &PropertyKeys.storageInterface, inObject: self ) @@ -46,7 +46,7 @@ extension NSPersistentStore { } set { - cs_setAssociatedRetainedObject( + Internals.setAssociatedRetainedObject( StorageObject(newValue), forKey: &PropertyKeys.storageInterface, inObject: self diff --git a/Sources/ObjectMonitor.swift b/Sources/ObjectMonitor.swift index df9518b..ffa36c4 100644 --- a/Sources/ObjectMonitor.swift +++ b/Sources/ObjectMonitor.swift @@ -170,9 +170,9 @@ public final class ObjectMonitor: Equatable { internal func registerObserver(_ observer: U, willChangeObject: @escaping (_ observer: U, _ monitor: ObjectMonitor, _ object: ObjectType) -> Void, didDeleteObject: @escaping (_ observer: U, _ monitor: ObjectMonitor, _ object: ObjectType) -> Void, didUpdateObject: @escaping (_ observer: U, _ monitor: ObjectMonitor, _ object: ObjectType, _ changedPersistentKeys: Set) -> Void) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to add an observer of type \(cs_typeName(observer as AnyObject)) outside the main thread." + "Attempted to add an observer of type \(Internals.typeName(observer as AnyObject)) outside the main thread." ) self.registerChangeNotification( &self.willChangeObjectKey, @@ -231,15 +231,15 @@ public final class ObjectMonitor: Equatable { internal func unregisterObserver(_ observer: AnyObject) { - CoreStore.assert( + Internals.assert( Thread.isMainThread, - "Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread." + "Attempted to remove an observer of type \(Internals.typeName(observer)) outside the main thread." ) let nilValue: AnyObject? = nil - cs_setAssociatedRetainedObject(nilValue, forKey: &self.willChangeObjectKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer) - cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.willChangeObjectKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer) + Internals.setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer) } deinit { @@ -250,8 +250,8 @@ public final class ObjectMonitor: Equatable { // MARK: Private - private let fetchedResultsController: CoreStoreFetchedResultsController - private let fetchedResultsControllerDelegate: FetchedResultsControllerDelegate + private let fetchedResultsController: Internals.CoreStoreFetchedResultsController + private let fetchedResultsControllerDelegate: Internals.FetchedResultsControllerDelegate private var lastCommittedAttributes = [String: NSObject]() private var willChangeObjectKey: Void? @@ -261,7 +261,7 @@ public final class ObjectMonitor: Equatable { private init(context: NSManagedObjectContext, object: ObjectType) { let objectID = object.cs_id() - let fetchRequest = CoreStoreFetchRequest() + let fetchRequest = Internals.CoreStoreFetchRequest() fetchRequest.entity = objectID.entity fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectResultType @@ -269,14 +269,14 @@ public final class ObjectMonitor: Equatable { fetchRequest.includesPendingChanges = false fetchRequest.shouldRefreshRefetchedObjects = true - let fetchedResultsController = CoreStoreFetchedResultsController( + let fetchedResultsController = Internals.CoreStoreFetchedResultsController( context: context, fetchRequest: fetchRequest, from: From([objectID.persistentStore?.configurationName]), applyFetchClauses: Where("SELF", isEqualTo: objectID).applyToFetchRequest ) - let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate() + let fetchedResultsControllerDelegate = Internals.FetchedResultsControllerDelegate() self.fetchedResultsController = fetchedResultsController self.fetchedResultsControllerDelegate = fetchedResultsControllerDelegate @@ -290,8 +290,8 @@ public final class ObjectMonitor: Equatable { private func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ObjectMonitor) -> Void) { - cs_setAssociatedRetainedObject( - NotificationObserver( + Internals.setAssociatedRetainedObject( + Internals.NotificationObserver( notificationName: name, object: self, closure: { [weak self] _ in @@ -310,8 +310,8 @@ public final class ObjectMonitor: Equatable { private func registerObjectNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ObjectMonitor, _ object: ObjectType) -> Void) { - cs_setAssociatedRetainedObject( - NotificationObserver( + Internals.setAssociatedRetainedObject( + Internals.NotificationObserver( notificationName: name, object: self, closure: { [weak self] (note) in diff --git a/Sources/OrderBy.swift b/Sources/OrderBy.swift index 19167d9..8c7564e 100644 --- a/Sources/OrderBy.swift +++ b/Sources/OrderBy.swift @@ -113,9 +113,9 @@ public struct OrderBy: OrderByClause, FetchClause, QueryClause if let sortDescriptors = fetchRequest.sortDescriptors, sortDescriptors != self.sortDescriptors { - CoreStore.log( + Internals.log( .warning, - message: "Existing sortDescriptors for the \(cs_typeName(fetchRequest)) was overwritten by \(cs_typeName(self)) query clause." + message: "Existing sortDescriptors for the \(Internals.typeName(fetchRequest)) was overwritten by \(Internals.typeName(self)) query clause." ) } diff --git a/Sources/Progress+Convenience.swift b/Sources/Progress+Convenience.swift index 4dca137..9f383b4 100644 --- a/Sources/Progress+Convenience.swift +++ b/Sources/Progress+Convenience.swift @@ -54,14 +54,14 @@ extension Progress { get { - let object: ProgressObserver? = cs_getAssociatedObjectForKey(&PropertyKeys.progressObserver, inObject: self) + let object: ProgressObserver? = Internals.getAssociatedObjectForKey(&PropertyKeys.progressObserver, inObject: self) if let observer = object { return observer } let observer = ProgressObserver(self) - cs_setAssociatedRetainedObject( + Internals.setAssociatedRetainedObject( observer, forKey: &PropertyKeys.progressObserver, inObject: self diff --git a/Sources/Relationship.swift b/Sources/Relationship.swift index 6dfec8a..ae130a8 100644 --- a/Sources/Relationship.swift +++ b/Sources/Relationship.swift @@ -269,15 +269,15 @@ public enum RelationshipContainer { get { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) return object.getValue( forKvcKey: self.keyPath, @@ -287,19 +287,19 @@ public enum RelationshipContainer { } set { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) - CoreStore.assert( + Internals.assert( object.isEditableInContext() == true, - "Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction." + "Attempted to update a \(Internals.typeName(O.self))'s value from outside a transaction." ) object.setValue( newValue, @@ -556,15 +556,15 @@ public enum RelationshipContainer { get { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) return object.getValue( forKvcKey: self.keyPath, @@ -574,19 +574,19 @@ public enum RelationshipContainer { } set { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) - CoreStore.assert( + Internals.assert( object.isEditableInContext() == true, - "Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction." + "Attempted to update a \(Internals.typeName(O.self))'s value from outside a transaction." ) object.setValue( newValue, @@ -848,15 +848,15 @@ public enum RelationshipContainer { get { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) return object.getValue( forKvcKey: self.keyPath, @@ -866,19 +866,19 @@ public enum RelationshipContainer { } set { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) - CoreStore.assert( + Internals.assert( object.isEditableInContext() == true, - "Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction." + "Attempted to update a \(Internals.typeName(O.self))'s value from outside a transaction." ) object.setValue( newValue, diff --git a/Sources/SQLiteStore.swift b/Sources/SQLiteStore.swift index 867a7f8..4cf4a9e 100644 --- a/Sources/SQLiteStore.swift +++ b/Sources/SQLiteStore.swift @@ -303,7 +303,7 @@ public final class SQLiteStore: LocalStorage { // MARK: Internal - internal static let defaultRootDirectory: URL = cs_lazy { + internal static let defaultRootDirectory: URL = Internals.with { #if os(tvOS) let systemDirectorySearchPath = FileManager.SearchPathDirectory.cachesDirectory @@ -328,7 +328,7 @@ public final class SQLiteStore: LocalStorage { ) .appendingPathExtension("sqlite") - internal static let legacyDefaultRootDirectory: URL = cs_lazy { + internal static let legacyDefaultRootDirectory: URL = Internals.with { #if os(tvOS) let systemDirectorySearchPath = FileManager.SearchPathDirectory.cachesDirectory @@ -341,7 +341,7 @@ public final class SQLiteStore: LocalStorage { in: .userDomainMask).first! } - internal static let legacyDefaultFileURL = cs_lazy { + internal static let legacyDefaultFileURL = Internals.with { return SQLiteStore.legacyDefaultRootDirectory .appendingPathComponent(DataStack.applicationName, isDirectory: false) diff --git a/Sources/SchemaHistory.swift b/Sources/SchemaHistory.swift index 4773477..22cb42c 100644 --- a/Sources/SchemaHistory.swift +++ b/Sources/SchemaHistory.swift @@ -92,17 +92,17 @@ public final class SchemaHistory: ExpressibleByArrayLiteral { if allSchema.isEmpty { - CoreStore.abort("The \"allSchema\" argument of the \(cs_typeName(SchemaHistory.self)) initializer cannot be empty.") + Internals.abort("The \"allSchema\" argument of the \(Internals.typeName(SchemaHistory.self)) initializer cannot be empty.") } - CoreStore.assert( + Internals.assert( migrationChain.isValid, - "Invalid migration chain passed to the \(cs_typeName(SchemaHistory.self)). Check that the model versions' order are correct and that no repetitions or ambiguities exist." + "Invalid migration chain passed to the \(Internals.typeName(SchemaHistory.self)). Check that the model versions' order are correct and that no repetitions or ambiguities exist." ) var schemaByVersion: [ModelVersion: DynamicSchema] = [:] for schema in allSchema { let modelVersion = schema.modelVersion - CoreStore.assert( + Internals.assert( schemaByVersion[modelVersion] == nil, "Multiple model schema found for model version \"\(modelVersion)\"." ) @@ -114,11 +114,11 @@ public final class SchemaHistory: ExpressibleByArrayLiteral { if !migrationChain.isEmpty && !migrationChain.contains(exactCurrentModelVersion) { - CoreStore.abort("An \"exactCurrentModelVersion\" argument was provided to \(cs_typeName(SchemaHistory.self)) initializer but a matching schema could not be found from the provided \(cs_typeName(MigrationChain.self)).") + Internals.abort("An \"exactCurrentModelVersion\" argument was provided to \(Internals.typeName(SchemaHistory.self)) initializer but a matching schema could not be found from the provided \(Internals.typeName(MigrationChain.self)).") } if schemaByVersion[exactCurrentModelVersion] == nil { - CoreStore.abort("An \"exactCurrentModelVersion\" argument was provided to \(cs_typeName(SchemaHistory.self)) initializer but a matching schema could not be found from the \(cs_typeName(DynamicSchema.self)) list.") + Internals.abort("An \"exactCurrentModelVersion\" argument was provided to \(Internals.typeName(SchemaHistory.self)) initializer but a matching schema could not be found from the \(Internals.typeName(DynamicSchema.self)) list.") } currentModelVersion = exactCurrentModelVersion } @@ -132,13 +132,13 @@ public final class SchemaHistory: ExpressibleByArrayLiteral { switch candidateVersions.count { case 0: - CoreStore.abort("None of the \(cs_typeName(MigrationChain.self)) leaf versions provided to the \(cs_typeName(SchemaHistory.self)) initializer matches any scheme from the \(cs_typeName(DynamicSchema.self)) list.") + Internals.abort("None of the \(Internals.typeName(MigrationChain.self)) leaf versions provided to the \(Internals.typeName(SchemaHistory.self)) initializer matches any scheme from the \(Internals.typeName(DynamicSchema.self)) list.") case 1: currentModelVersion = candidateVersions.first! default: - CoreStore.abort("Could not resolve the \(cs_typeName(SchemaHistory.self)) current model version because the \(cs_typeName(MigrationChain.self)) have ambiguous leaf versions: \(candidateVersions)") + Internals.abort("Could not resolve the \(Internals.typeName(SchemaHistory.self)) current model version because the \(Internals.typeName(MigrationChain.self)) have ambiguous leaf versions: \(candidateVersions)") } } @@ -168,12 +168,12 @@ public final class SchemaHistory: ExpressibleByArrayLiteral { internal let schemaByVersion: [ModelVersion: DynamicSchema] internal let rawModel: NSManagedObjectModel - internal private(set) lazy var entityDescriptionsByEntityIdentifier: [EntityIdentifier: NSEntityDescription] = cs_lazy { [unowned self] in + internal private(set) lazy var entityDescriptionsByEntityIdentifier: [Internals.EntityIdentifier: NSEntityDescription] = Internals.with { [unowned self] in - var mapping: [EntityIdentifier: NSEntityDescription] = [:] + var mapping: [Internals.EntityIdentifier: NSEntityDescription] = [:] self.rawModel.entities.forEach { (entityDescription) in - let entityIdentifier = EntityIdentifier(entityDescription) + let entityIdentifier = Internals.EntityIdentifier(entityDescription) mapping[entityIdentifier] = entityDescription } return mapping diff --git a/Sources/Select.swift b/Sources/Select.swift index 1edc2fb..c0f8627 100644 --- a/Sources/Select.swift +++ b/Sources/Select.swift @@ -781,9 +781,9 @@ public struct Select: SelectClause, Hasha } else { - CoreStore.log( + Internals.log( .warning, - message: "The key path \"\(keyPath)\" could not be resolved in entity \(cs_typeName(entityDescription.managedObjectClassName)) as an attribute and will be ignored by \(cs_typeName(self)) query clause." + message: "The key path \"\(keyPath)\" could not be resolved in entity \(Internals.typeName(entityDescription.managedObjectClassName)) as an attribute and will be ignored by \(Internals.typeName(self)) query clause." ) } diff --git a/Sources/NSFetchedResultsController+ObjectiveC.swift b/Sources/Shared.swift similarity index 52% rename from Sources/NSFetchedResultsController+ObjectiveC.swift rename to Sources/Shared.swift index b71c943..604a5ec 100644 --- a/Sources/NSFetchedResultsController+ObjectiveC.swift +++ b/Sources/Shared.swift @@ -1,5 +1,5 @@ // -// NSFetchedResultsController+ObjectiveC.swift +// Shared.swift // CoreStore // // Copyright © 2018 John Rommel Estropia @@ -24,28 +24,47 @@ // import Foundation -import CoreData - - -// MARK: - Private -@available(macOS 10.12, *) -fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: CSFrom, sectionBy: CSSectionBy?, fetchClauses: [CSFetchClause]) -> NSFetchedResultsController { - - let controller = CoreStoreFetchedResultsController( - context: context, - fetchRequest: CoreStoreFetchRequest(), - from: from.bridgeToSwift, - sectionBy: sectionBy?.bridgeToSwift, - applyFetchClauses: { (fetchRequest) in - - fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - CoreStore.assert( - fetchRequest.sortDescriptors?.isEmpty == false, - "An \(cs_typeName(NSFetchedResultsController.self)) requires a sort information. Specify from a \(cs_typeName(CSOrderBy.self)) clause or any custom \(cs_typeName(CSFetchClause.self)) that provides a sort descriptor." - ) + +// MARK: - Shared + +/** +Global utilities +*/ +public enum Shared { + + /** + The `CoreStoreLogger` instance to be used. The default logger is an instance of a `DefaultLogger`. + */ + public static var logger: CoreStoreLogger = DefaultLogger() + + @available(*, deprecated, message: "Call methods directly from the DataStack instead") + public static var defaultStack: DataStack { + + get { + + self.defaultStackBarrierQueue.sync(flags: .barrier) { + + if self.defaultStackInstance == nil { + + self.defaultStackInstance = DataStack() + } + } + return self.defaultStackInstance! } - ) - return controller.dynamicCast() + set { + + self.defaultStackBarrierQueue.async(flags: .barrier) { + + self.defaultStackInstance = newValue + } + } + } + + + // MARK: Private + + private static let defaultStackBarrierQueue = DispatchQueue.concurrent("com.coreStore.defaultStackBarrierQueue") + + private static var defaultStackInstance: DataStack? } diff --git a/Sources/SynchronousDataTransaction.swift b/Sources/SynchronousDataTransaction.swift index d99ae0a..c8970de 100644 --- a/Sources/SynchronousDataTransaction.swift +++ b/Sources/SynchronousDataTransaction.swift @@ -57,9 +57,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction { */ public override func create(_ into: Into) -> D { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to create an entity of type \(cs_typeName(into.entityClass)) from an already committed \(cs_typeName(self))." + "Attempted to create an entity of type \(Internals.typeName(into.entityClass)) from an already committed \(Internals.typeName(self))." ) return super.create(into) @@ -73,9 +73,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction { */ public override func edit(_ object: D?) -> D? { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to update an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))." + "Attempted to update an entity of type \(Internals.typeName(object)) from an already committed \(Internals.typeName(self))." ) return super.edit(object) @@ -90,9 +90,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction { */ public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> D? { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to update an entity of type \(cs_typeName(into.entityClass)) from an already committed \(cs_typeName(self))." + "Attempted to update an entity of type \(Internals.typeName(into.entityClass)) from an already committed \(Internals.typeName(self))." ) return super.edit(into, objectID) @@ -105,9 +105,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction { */ public override func delete(_ object: D?) { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to delete an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))." + "Attempted to delete an entity of type \(Internals.typeName(object)) from an already committed \(Internals.typeName(self))." ) super.delete(object) @@ -122,9 +122,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction { */ public override func delete(_ object1: D?, _ object2: D?, _ objects: D?...) { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to delete an entities from an already committed \(cs_typeName(self))." + "Attempted to delete an entities from an already committed \(Internals.typeName(self))." ) super.delete(([object1, object2] + objects).compactMap { $0 }) @@ -137,9 +137,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction { */ public override func delete(_ objects: S) where S.Iterator.Element: DynamicObject { - CoreStore.assert( + Internals.assert( !self.isCommitted, - "Attempted to delete an entities from an already committed \(cs_typeName(self))." + "Attempted to delete an entities from an already committed \(Internals.typeName(self))." ) super.delete(objects) diff --git a/Sources/Transformable.swift b/Sources/Transformable.swift index 3f27575..7cd6779 100644 --- a/Sources/Transformable.swift +++ b/Sources/Transformable.swift @@ -144,15 +144,15 @@ public enum TransformableContainer { get { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) if let customGetter = self.customGetter { @@ -163,19 +163,19 @@ public enum TransformableContainer { } set { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) - CoreStore.assert( + Internals.assert( object.isEditableInContext() == true, - "Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction." + "Attempted to update a \(Internals.typeName(O.self))'s value from outside a transaction." ) if let customSetter = self.customSetter { @@ -226,7 +226,7 @@ public enum TransformableContainer { internal let affectedByKeyPaths: () -> Set internal var rawObject: CoreStoreManagedObject? - internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = cs_lazy { [unowned self] in + internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in guard let customGetter = self.customGetter else { @@ -246,7 +246,7 @@ public enum TransformableContainer { } } - internal private(set) lazy var setter: CoreStoreManagedObject.CustomSetter? = cs_lazy { [unowned self] in + internal private(set) lazy var setter: CoreStoreManagedObject.CustomSetter? = Internals.with { [unowned self] in guard let customSetter = self.customSetter else { @@ -357,15 +357,15 @@ public enum TransformableContainer { get { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) if let customGetter = self.customGetter { @@ -376,19 +376,19 @@ public enum TransformableContainer { } set { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) - CoreStore.assert( + Internals.assert( object.isEditableInContext() == true, - "Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction." + "Attempted to update a \(Internals.typeName(O.self))'s value from outside a transaction." ) if let customSetter = self.customSetter { @@ -439,7 +439,7 @@ public enum TransformableContainer { internal let affectedByKeyPaths: () -> Set internal var rawObject: CoreStoreManagedObject? - internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = cs_lazy { [unowned self] in + internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in guard let customGetter = self.customGetter else { @@ -459,7 +459,7 @@ public enum TransformableContainer { } } - internal private(set) lazy var setter: CoreStoreManagedObject.CustomSetter? = cs_lazy { [unowned self] in + internal private(set) lazy var setter: CoreStoreManagedObject.CustomSetter? = Internals.with { [unowned self] in guard let customSetter = self.customSetter else { diff --git a/Sources/UnsafeDataTransaction+Observing.swift b/Sources/UnsafeDataTransaction+Observing.swift index ab38c6b..e51af42 100644 --- a/Sources/UnsafeDataTransaction+Observing.swift +++ b/Sources/UnsafeDataTransaction+Observing.swift @@ -67,7 +67,7 @@ extension UnsafeDataTransaction { */ public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { - CoreStore.assert( + Internals.assert( fetchClauses.filter { $0 is OrderBy }.count > 0, "A ListMonitor requires an OrderBy clause." ) @@ -126,7 +126,7 @@ extension UnsafeDataTransaction { */ public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { - CoreStore.assert( + Internals.assert( fetchClauses.filter { $0 is OrderBy }.count > 0, "A ListMonitor requires an OrderBy clause." ) @@ -191,7 +191,7 @@ extension UnsafeDataTransaction { */ public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { - CoreStore.assert( + Internals.assert( fetchClauses.filter { $0 is OrderBy }.count > 0, "A ListMonitor requires an OrderBy clause." ) @@ -252,7 +252,7 @@ extension UnsafeDataTransaction { */ public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { - CoreStore.assert( + Internals.assert( fetchClauses.filter { $0 is OrderBy }.count > 0, "A ListMonitor requires an OrderBy clause." ) diff --git a/Sources/UnsafeDataTransaction.swift b/Sources/UnsafeDataTransaction.swift index 5228492..103bce2 100644 --- a/Sources/UnsafeDataTransaction.swift +++ b/Sources/UnsafeDataTransaction.swift @@ -68,9 +68,9 @@ public final class UnsafeDataTransaction: BaseDataTransaction { */ public func rollback() { - CoreStore.assert( + Internals.assert( self.supportsUndo, - "Attempted to rollback a \(cs_typeName(self)) with Undo support disabled." + "Attempted to rollback a \(Internals.typeName(self)) with Undo support disabled." ) self.context.rollback() } @@ -80,9 +80,9 @@ public final class UnsafeDataTransaction: BaseDataTransaction { */ public func undo() { - CoreStore.assert( + Internals.assert( self.supportsUndo, - "Attempted to undo a \(cs_typeName(self)) with Undo support disabled." + "Attempted to undo a \(Internals.typeName(self)) with Undo support disabled." ) self.context.undo() } @@ -116,9 +116,9 @@ public final class UnsafeDataTransaction: BaseDataTransaction { */ public func redo() { - CoreStore.assert( + Internals.assert( self.supportsUndo, - "Attempted to redo a \(cs_typeName(self)) with Undo support disabled." + "Attempted to redo a \(Internals.typeName(self)) with Undo support disabled." ) self.context.redo() } diff --git a/Sources/Value.swift b/Sources/Value.swift index 6945299..a6f5164 100644 --- a/Sources/Value.swift +++ b/Sources/Value.swift @@ -137,15 +137,15 @@ public enum ValueContainer { get { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) if let customGetter = self.customGetter { @@ -158,19 +158,19 @@ public enum ValueContainer { } set { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) - CoreStore.assert( + Internals.assert( object.isEditableInContext() == true, - "Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction." + "Attempted to update a \(Internals.typeName(O.self))'s value from outside a transaction." ) if let customSetter = self.customSetter { @@ -221,7 +221,7 @@ public enum ValueContainer { internal let affectedByKeyPaths: () -> Set internal var rawObject: CoreStoreManagedObject? - internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = cs_lazy { [unowned self] in + internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in guard let customGetter = self.customGetter else { @@ -241,7 +241,7 @@ public enum ValueContainer { } } - internal private(set) lazy var setter: CoreStoreManagedObject.CustomSetter? = cs_lazy { [unowned self] in + internal private(set) lazy var setter: CoreStoreManagedObject.CustomSetter? = Internals.with { [unowned self] in guard let customSetter = self.customSetter else { @@ -351,15 +351,15 @@ public enum ValueContainer { get { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) if let customGetter = self.customGetter { @@ -371,19 +371,19 @@ public enum ValueContainer { } set { - CoreStore.assert( + Internals.assert( self.rawObject != nil, - "Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." + "Attempted to access values from a \(Internals.typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types." ) return withExtendedLifetime(self.rawObject!) { (object) in - CoreStore.assert( + Internals.assert( object.isRunningInAllowedQueue() == true, - "Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue." + "Attempted to access \(Internals.typeName(O.self))'s value outside it's designated queue." ) - CoreStore.assert( + Internals.assert( object.isEditableInContext() == true, - "Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction." + "Attempted to update a \(Internals.typeName(O.self))'s value from outside a transaction." ) if let customSetter = self.customSetter { @@ -434,7 +434,7 @@ public enum ValueContainer { internal let affectedByKeyPaths: () -> Set internal var rawObject: CoreStoreManagedObject? - internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = cs_lazy { [unowned self] in + internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = Internals.with { [unowned self] in guard let customGetter = self.customGetter else { @@ -454,7 +454,7 @@ public enum ValueContainer { } } - internal private(set) lazy var setter: CoreStoreManagedObject.CustomSetter? = cs_lazy { [unowned self] in + internal private(set) lazy var setter: CoreStoreManagedObject.CustomSetter? = Internals.with { [unowned self] in guard let customSetter = self.customSetter else { diff --git a/Sources/Where.swift b/Sources/Where.swift index 7dfd06a..b882fce 100644 --- a/Sources/Where.swift +++ b/Sources/Where.swift @@ -278,9 +278,9 @@ public struct Where: WhereClauseType, FetchClause, QueryClause if let predicate = fetchRequest.predicate, predicate != self.predicate { - CoreStore.log( + Internals.log( .warning, - message: "An existing predicate for the \(cs_typeName(fetchRequest)) was overwritten by \(cs_typeName(self)) query clause." + message: "An existing predicate for the \(Internals.typeName(fetchRequest)) was overwritten by \(Internals.typeName(self)) query clause." ) } diff --git a/Sources/XcodeDataModelSchema.swift b/Sources/XcodeDataModelSchema.swift index e17bbb7..027b229 100644 --- a/Sources/XcodeDataModelSchema.swift +++ b/Sources/XcodeDataModelSchema.swift @@ -54,7 +54,7 @@ public final class XcodeDataModelSchema: DynamicSchema { let foundModels = bundle .paths(forResourcesOfType: "momd", inDirectory: nil) .map({ ($0 as NSString).lastPathComponent }) - CoreStore.abort("Could not find \"\(modelName).momd\" from the bundle \"\(bundle.bundleIdentifier ?? "")\". Other model files in bundle: \(foundModels.coreStoreDumpString)") + Internals.abort("Could not find \"\(modelName).momd\" from the bundle \"\(bundle.bundleIdentifier ?? "")\". Other model files in bundle: \(foundModels.coreStoreDumpString)") } let modelFileURL = URL(fileURLWithPath: modelFilePath) @@ -63,7 +63,7 @@ public final class XcodeDataModelSchema: DynamicSchema { guard let versionInfo = NSDictionary(contentsOf: versionInfoPlistURL), let versionHashes = versionInfo["NSManagedObjectModel_VersionHashes"] as? [String: AnyObject] else { - CoreStore.abort("Could not load \(cs_typeName(NSManagedObjectModel.self)) metadata from path \"\(versionInfoPlistURL)\".") + Internals.abort("Could not load \(Internals.typeName(NSManagedObjectModel.self)) metadata from path \"\(versionInfoPlistURL)\".") } let modelVersions = Set(versionHashes.keys) @@ -76,9 +76,9 @@ public final class XcodeDataModelSchema: DynamicSchema { } else if let resolvedVersion = modelVersions.intersection(modelVersionHints).first { - CoreStore.log( + Internals.log( .warning, - message: "The \(cs_typeName(MigrationChain.self)) leaf versions do not include the model file's current version. Resolving to version \"\(resolvedVersion)\"." + message: "The \(Internals.typeName(MigrationChain.self)) leaf versions do not include the model file's current version. Resolving to version \"\(resolvedVersion)\"." ) currentModelVersion = resolvedVersion } @@ -86,16 +86,16 @@ public final class XcodeDataModelSchema: DynamicSchema { if !modelVersionHints.isEmpty { - CoreStore.log( + Internals.log( .warning, - message: "The \(cs_typeName(MigrationChain.self)) leaf versions do not include any of the model file's embedded versions. Resolving to version \"\(resolvedVersion)\"." + message: "The \(Internals.typeName(MigrationChain.self)) leaf versions do not include any of the model file's embedded versions. Resolving to version \"\(resolvedVersion)\"." ) } currentModelVersion = resolvedVersion } else { - CoreStore.abort("No model files were found in URL \"\(modelFileURL)\".") + Internals.abort("No model files were found in URL \"\(modelFileURL)\".") } var allSchema: [XcodeDataModelSchema] = [] for modelVersion in modelVersions { @@ -124,7 +124,7 @@ public final class XcodeDataModelSchema: DynamicSchema { let foundModels = bundle .paths(forResourcesOfType: "momd", inDirectory: nil) .map({ ($0 as NSString).lastPathComponent }) - CoreStore.abort("Could not find \"\(modelName).momd\" from the bundle \"\(bundle.bundleIdentifier ?? "")\". Other model files in bundle: \(foundModels.coreStoreDumpString)") + Internals.abort("Could not find \"\(modelName).momd\" from the bundle \"\(bundle.bundleIdentifier ?? "")\". Other model files in bundle: \(foundModels.coreStoreDumpString)") } let modelFileURL = URL(fileURLWithPath: modelFilePath) @@ -144,7 +144,7 @@ public final class XcodeDataModelSchema: DynamicSchema { */ public required init(modelName: ModelVersion, modelVersionFileURL: URL) { - CoreStore.assert( + Internals.assert( NSManagedObjectModel(contentsOf: modelVersionFileURL) != nil, "Could not find the \"\(modelName).mom\" version file for the model at URL \"\(modelVersionFileURL)\"." ) @@ -169,7 +169,7 @@ public final class XcodeDataModelSchema: DynamicSchema { self.cachedRawModel = rawModel return rawModel } - CoreStore.abort("Could not create an \(cs_typeName(NSManagedObjectModel.self)) from the model at URL \"\(self.modelVersionFileURL)\".") + Internals.abort("Could not create an \(Internals.typeName(NSManagedObjectModel.self)) from the model at URL \"\(self.modelVersionFileURL)\".") } @@ -177,7 +177,7 @@ public final class XcodeDataModelSchema: DynamicSchema { internal let modelVersionFileURL: URL - private lazy var rootModelFileURL: URL = cs_lazy { [unowned self] in + private lazy var rootModelFileURL: URL = Internals.with { [unowned self] in return self.modelVersionFileURL.deletingLastPathComponent() }