From 0073d038e0c15212f0f0b81205208ab67b947999 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Thu, 5 May 2016 09:44:14 +0800 Subject: [PATCH] WIP: logging utilities --- CoreStore.xcodeproj/project.pbxproj | 24 +- .../xcschemes/CoreStore iOS7.xcscheme | 4 +- CoreStoreDemo/CoreStoreDemo/AppDelegate.swift | 8 + CoreStoreTests/CoreStoreTests.swift | 6 +- .../Convenience/NSProgress+Convenience.swift | 4 +- Sources/CoreStoreError.swift | 19 +- .../BaseDataTransaction+Querying.swift | 22 +- .../Concrete Clauses/GroupBy.swift | 2 +- .../Concrete Clauses/OrderBy.swift | 2 +- .../Concrete Clauses/Select.swift | 4 +- .../Concrete Clauses/Where.swift | 2 +- .../DataStack+Querying.swift | 28 +- .../BaseDataTransaction+Importing.swift | 30 +- Sources/Internal/AssociatedObjects.swift | 68 --- Sources/Internal/CoreStoreFetchRequest.swift | 1 + .../CoreStoreFetchedResultsController.swift | 8 +- .../FetchedResultsControllerDelegate.swift | 22 +- Sources/Internal/Functions.swift | 80 +++- .../NSManagedObjectContext+CoreStore.swift | 8 +- .../NSManagedObjectContext+Querying.swift | 4 +- .../NSManagedObjectContext+Setup.swift | 12 +- .../NSManagedObjectContext+Transaction.swift | 8 +- .../Internal/NSManagedObjectModel+Setup.swift | 20 +- .../Internal/NSPersistentStore+Setup.swift | 6 +- .../NSPersistentStoreCoordinator+Setup.swift | 4 +- ...reStore+CustomDebugStringConvertible.swift | 409 ++++++++++++++++++ Sources/Logging/CoreStoreLogger.swift | 23 - Sources/Migrating/DataStack+Migration.swift | 30 +- Sources/Migrating/MigrationChain.swift | 6 +- .../CSBaseDataTransaction+Querying.swift | 12 +- .../ObjectiveC/CSCoreStore+Migrating.swift | 6 +- .../ObjectiveC/CSDataStack+Migrating.swift | 15 +- .../ObjectiveC/CSDataStack+Observing.swift | 8 +- Sources/ObjectiveC/CSDataStack+Querying.swift | 14 +- Sources/Observing/DataStack+Observing.swift | 10 +- Sources/Observing/ListMonitor.swift | 64 +-- Sources/Observing/ObjectMonitor.swift | 14 +- Sources/Setup/DataStack.swift | 16 +- .../Setup/StorageInterfaces/ICloudStore.swift | 32 +- .../ICloudStoreObserver.swift | 4 + .../StorageInterfaces/LegacySQLiteStore.swift | 2 +- .../Setup/StorageInterfaces/SQLiteStore.swift | 2 +- .../AsynchronousDataTransaction.swift | 28 +- .../Transactions/BaseDataTransaction.swift | 64 +-- .../SynchronousDataTransaction.swift | 26 +- .../Transactions/UnsafeDataTransaction.swift | 6 +- 46 files changed, 791 insertions(+), 396 deletions(-) delete mode 100644 Sources/Internal/AssociatedObjects.swift create mode 100644 Sources/Logging/CoreStore+CustomDebugStringConvertible.swift diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index 1d66518..8ecec76 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -56,7 +56,6 @@ 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 /* NSProgress+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6A81B50A4B300714891 /* NSProgress+Convenience.swift */; }; - 82BA18CD1C4BBD7100A0916E /* AssociatedObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2A1AFF849C0064E85B /* AssociatedObjects.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 */; }; @@ -95,6 +94,11 @@ B519E45A1C4CD2DA00E7B469 /* GCDKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B519E4571C4CD2CA00E7B469 /* GCDKit.framework */; }; B519E45B1C4CD2ED00E7B469 /* GCDKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B519E4571C4CD2CA00E7B469 /* GCDKit.framework */; }; B51BE06A1B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */; }; + B51FE5AB1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; + B51FE5AC1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; + B51FE5AD1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; + B51FE5AE1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; + B51FE5AF1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */; }; B5202CFA1C04688100DED140 /* NSFetchedResultsController+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */; }; B5202CFD1C046E8400DED140 /* NSFetchedResultsController+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */; }; B52661401CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */; }; @@ -146,7 +150,6 @@ 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 /* NSProgress+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6A81B50A4B300714891 /* NSProgress+Convenience.swift */; }; - B52DD1BF1BE1F94600949AFE /* AssociatedObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2A1AFF849C0064E85B /* AssociatedObjects.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 */; }; @@ -279,7 +282,6 @@ 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 /* NSProgress+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FAD6A81B50A4B300714891 /* NSProgress+Convenience.swift */; }; - B56321AA1BD6521C006C9394 /* AssociatedObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2A1AFF849C0064E85B /* AssociatedObjects.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 */; }; @@ -401,7 +403,6 @@ B5D9E3261CA2C317007A9D52 /* AsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84EEA1AFF846E0064E85B /* AsynchronousDataTransaction.swift */; }; B5D9E3271CA2C317007A9D52 /* CoreStore+Querying.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F071AFF847B0064E85B /* CoreStore+Querying.swift */; }; B5D9E3281CA2C317007A9D52 /* ListObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F1E1AFF84860064E85B /* ListObserver.swift */; }; - B5D9E3291CA2C317007A9D52 /* AssociatedObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2A1AFF849C0064E85B /* AssociatedObjects.swift */; }; B5D9E32C1CA2C317007A9D52 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D39A0119FD00C9000E91BB /* Foundation.framework */; }; B5D9E32D1CA2C317007A9D52 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F03A54C19C5C872005002A5 /* CoreData.framework */; }; B5D9E32F1CA2C317007A9D52 /* CoreStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 2F03A53519C5C6DA005002A5 /* CoreStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -487,7 +488,6 @@ 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 */; }; - B5E84F2E1AFF849C0064E85B /* AssociatedObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2A1AFF849C0064E85B /* AssociatedObjects.swift */; }; B5E84F2F1AFF849C0064E85B /* NotificationObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2B1AFF849C0064E85B /* 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 */; }; @@ -632,6 +632,7 @@ B504D0D51B02362500B2BBB1 /* CoreStore+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+Setup.swift"; sourceTree = ""; }; B519E4571C4CD2CA00E7B469 /* GCDKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GCDKit.framework; path = "../../Library/Developer/Xcode/DerivedData/Build/Products/Debug-iphoneos/GCDKit.framework"; sourceTree = ""; }; B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectModel+Setup.swift"; sourceTree = ""; }; + B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+CustomDebugStringConvertible.swift"; sourceTree = ""; }; B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFetchedResultsController+Convenience.swift"; sourceTree = ""; }; B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreFetchRequest.swift; sourceTree = ""; }; B529C2031CA4A2DB007E7EBD /* CSSaveResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSaveResult.swift; sourceTree = ""; }; @@ -734,7 +735,6 @@ 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 = ""; }; - B5E84F2A1AFF849C0064E85B /* AssociatedObjects.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociatedObjects.swift; sourceTree = ""; }; B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 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 = ""; }; @@ -1112,6 +1112,7 @@ B5E84EE31AFF84610064E85B /* DefaultLogger.swift */, B5E84EE41AFF84610064E85B /* CoreStore+Logging.swift */, B5E84EE51AFF84610064E85B /* CoreStoreLogger.swift */, + B51FE5AA1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift */, ); path = Logging; sourceTree = ""; @@ -1193,7 +1194,6 @@ B5E84F291AFF849C0064E85B /* Internal */ = { isa = PBXGroup; children = ( - B5E84F2A1AFF849C0064E85B /* AssociatedObjects.swift */, B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */, B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */, B5E834BA1B7691F3001D3D50 /* Functions.swift */, @@ -1571,6 +1571,7 @@ B5ECDC051CA8138100C7F112 /* CSOrderBy.swift in Sources */, B5E1B5981CAA0C23007FD580 /* CSObjectObserver.swift in Sources */, B5519A5F1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */, + B51FE5AB1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */, B54A6A551BA15F2A007870FD /* FetchedResultsControllerDelegate.swift in Sources */, B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */, B53FBA0B1CAB5E6500F0D40A /* CSCoreStore+Migrating.swift in Sources */, @@ -1666,7 +1667,6 @@ B5ECDC0B1CA8161B00C7F112 /* CSGroupBy.swift in Sources */, B5E84F151AFF847B0064E85B /* CoreStore+Querying.swift in Sources */, B5E84F241AFF84860064E85B /* ListObserver.swift in Sources */, - B5E84F2E1AFF849C0064E85B /* AssociatedObjects.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1702,6 +1702,7 @@ B5ECDC071CA8138100C7F112 /* CSOrderBy.swift in Sources */, B5E1B59A1CAA0C23007FD580 /* CSObjectObserver.swift in Sources */, B5519A601CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */, + B51FE5AD1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */, B5FE4DAD1C85D44E00FA6A91 /* SQLiteStore.swift in Sources */, 82BA18C51C4BBD5300A0916E /* ListObserver.swift in Sources */, B53FBA0D1CAB5E6500F0D40A /* CSCoreStore+Migrating.swift in Sources */, @@ -1749,7 +1750,6 @@ 82BA18C91C4BBD5900A0916E /* MigrationType.swift in Sources */, 82BA18D01C4BBD7100A0916E /* MigrationManager.swift in Sources */, 82BA18C61C4BBD5900A0916E /* DataStack+Migration.swift in Sources */, - 82BA18CD1C4BBD7100A0916E /* AssociatedObjects.swift in Sources */, B59851491C90289D00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */, B5E1B5A41CAA4365007FD580 /* CSCoreStore+Observing.swift in Sources */, B5FEC18F1C9166E600532541 /* NSPersistentStore+Setup.swift in Sources */, @@ -1837,7 +1837,6 @@ B5A5F26A1CAEC50F004AB9AF /* CSSelect.swift in Sources */, B5FEC1911C9166E700532541 /* NSPersistentStore+Setup.swift in Sources */, B52DD1AB1BE1F93900949AFE /* From.swift in Sources */, - B52DD1BF1BE1F94600949AFE /* AssociatedObjects.swift in Sources */, B546F95B1C99B17400D5AC55 /* CSCoreStore+Setup.swift in Sources */, B52DD1A11BE1F92C00949AFE /* DataStack+Transaction.swift in Sources */, B5D3F6481C887C0A00C7492A /* LegacySQLiteStore.swift in Sources */, @@ -1910,6 +1909,7 @@ B598514B1C90289F00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */, B52DD1AA1BE1F93500949AFE /* ClauseTypes.swift in Sources */, B53FBA021CAB2D2F00F0D40A /* CSMigrationResult.swift in Sources */, + B51FE5AF1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1940,12 +1940,12 @@ B529C2071CA4A2DC007E7EBD /* CSSaveResult.swift in Sources */, B563219D1BD65216006C9394 /* DataStack+Observing.swift in Sources */, B56321961BD65216006C9394 /* From.swift in Sources */, - B56321AA1BD6521C006C9394 /* AssociatedObjects.swift in Sources */, B5ECDC021CA80CBA00C7F112 /* CSWhere.swift in Sources */, B5ECDC081CA8138100C7F112 /* CSOrderBy.swift in Sources */, B5E1B59B1CAA0C23007FD580 /* CSObjectObserver.swift in Sources */, B5519A611CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */, B5FE4DAE1C85D44E00FA6A91 /* SQLiteStore.swift in Sources */, + B51FE5AE1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */, B563218C1BD65216006C9394 /* DataStack+Transaction.swift in Sources */, B53FBA0E1CAB5E6500F0D40A /* CSCoreStore+Migrating.swift in Sources */, B563219E1BD65216006C9394 /* CoreStore+Observing.swift in Sources */, @@ -2097,6 +2097,7 @@ B53FBA0C1CAB5E6500F0D40A /* CSCoreStore+Migrating.swift in Sources */, B5D9E3041CA2C317007A9D52 /* NSFetchedResultsController+Convenience.swift in Sources */, B5D9E3051CA2C317007A9D52 /* (null) in Sources */, + B51FE5AC1CD4D00300E54258 /* CoreStore+CustomDebugStringConvertible.swift in Sources */, B5D9E3061CA2C317007A9D52 /* ObjectObserver.swift in Sources */, B5D9E3071CA2C317007A9D52 /* NotificationObserver.swift in Sources */, B53FBA051CAB300C00F0D40A /* CSMigrationType.swift in Sources */, @@ -2163,7 +2164,6 @@ B5D9E3261CA2C317007A9D52 /* AsynchronousDataTransaction.swift in Sources */, B5D9E3271CA2C317007A9D52 /* CoreStore+Querying.swift in Sources */, B5D9E3281CA2C317007A9D52 /* ListObserver.swift in Sources */, - B5D9E3291CA2C317007A9D52 /* AssociatedObjects.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore iOS7.xcscheme b/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore iOS7.xcscheme index 07b9206..f69a837 100644 --- a/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore iOS7.xcscheme +++ b/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore iOS7.xcscheme @@ -15,7 +15,7 @@ @@ -79,7 +79,7 @@ diff --git a/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift b/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift index 2f54f30..c320623 100644 --- a/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift +++ b/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift @@ -7,6 +7,7 @@ // import UIKit +import CoreStore // MARK: - AppDelegate @@ -21,6 +22,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { application.statusBarStyle = .LightContent + + + print(InMemoryStore()) + print(SQLiteStore()) + print(LocalStorageOptions.None) + print([.AllowSynchronousLightweightMigration, .PreventProgressiveMigration] as LocalStorageOptions) + return true } } diff --git a/CoreStoreTests/CoreStoreTests.swift b/CoreStoreTests/CoreStoreTests.swift index f96d947..0b5fa95 100644 --- a/CoreStoreTests/CoreStoreTests.swift +++ b/CoreStoreTests/CoreStoreTests.swift @@ -44,7 +44,10 @@ class CoreStoreTests: XCTestCase { func testExample() { - let stack = DataStack(modelName: "Model", bundle: NSBundle(forClass: self.dynamicType)) + let stack = DataStack( + modelName: "Model", + bundle: NSBundle(forClass: self.dynamicType) + ) CoreStore.defaultStack = stack XCTAssert(CoreStore.defaultStack === stack, "CoreStore.defaultStack === stack") @@ -200,7 +203,6 @@ class CoreStoreTests: XCTestCase { Select("testString", .Count("testString", As: "count")), GroupBy("testString") ) - print(counts) XCTAssertTrue(NSThread.isMainThread(), "NSThread.isMainThread()") switch result { diff --git a/Sources/Convenience/NSProgress+Convenience.swift b/Sources/Convenience/NSProgress+Convenience.swift index cd06165..66ec942 100644 --- a/Sources/Convenience/NSProgress+Convenience.swift +++ b/Sources/Convenience/NSProgress+Convenience.swift @@ -57,14 +57,14 @@ public extension NSProgress { get { - let object: ProgressObserver? = getAssociatedObjectForKey(&PropertyKeys.progressObserver, inObject: self) + let object: ProgressObserver? = cs_getAssociatedObjectForKey(&PropertyKeys.progressObserver, inObject: self) if let observer = object { return observer } let observer = ProgressObserver(self) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( observer, forKey: &PropertyKeys.progressObserver, inObject: self diff --git a/Sources/CoreStoreError.swift b/Sources/CoreStoreError.swift index 57048ab..2c854c1 100644 --- a/Sources/CoreStoreError.swift +++ b/Sources/CoreStoreError.swift @@ -32,7 +32,7 @@ import CoreData /** All errors thrown from CoreStore are expressed in `CoreStoreError` enum values. */ -public enum CoreStoreError: ErrorType, CustomStringConvertible, CustomDebugStringConvertible, Hashable { +public enum CoreStoreError: ErrorType, Hashable { /** A failure occured because of an unknown error. @@ -89,23 +89,6 @@ public enum CoreStoreError: ErrorType, CustomStringConvertible, CustomDebugStrin } - // MARK: CustomStringConvertible - - public var description: String { - - // TODO: - return self.bridgeToObjectiveC.description - } - - - // MARK: CustomDebugStringConvertible - - public var debugDescription: String { - - return self.description - } - - // MARK: Hashable public var hashValue: Int { diff --git a/Sources/Fetching and Querying/BaseDataTransaction+Querying.swift b/Sources/Fetching and Querying/BaseDataTransaction+Querying.swift index 40dfdbf..6106d6b 100644 --- a/Sources/Fetching and Querying/BaseDataTransaction+Querying.swift +++ b/Sources/Fetching and Querying/BaseDataTransaction+Querying.swift @@ -118,7 +118,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.context.fetchOne(from, fetchClauses) } @@ -148,7 +148,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.context.fetchAll(from, fetchClauses) } @@ -178,7 +178,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.context.fetchCount(from, fetchClauses) @@ -209,7 +209,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.context.fetchObjectID(from, fetchClauses) } @@ -239,7 +239,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.context.fetchObjectIDs(from, fetchClauses) } @@ -255,7 +255,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to delete from a \(typeName(self)) outside its designated queue." + "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." ) return self.context.deleteAll(from, deleteClauses) @@ -272,7 +272,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to delete from a \(typeName(self)) outside its designated queue." + "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." ) return self.context.deleteAll(from, deleteClauses) @@ -293,7 +293,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(typeName(self)) outside its designated queue." + "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) return self.context.queryValue(from, selectClause, queryClauses) @@ -314,7 +314,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(typeName(self)) outside its designated queue." + "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) return self.context.queryValue(from, selectClause, queryClauses) @@ -335,7 +335,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(typeName(self)) outside its designated queue." + "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) return self.context.queryAttributes(from, selectClause, queryClauses) @@ -356,7 +356,7 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to query from a \(typeName(self)) outside its designated queue." + "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) return self.context.queryAttributes(from, selectClause, queryClauses) diff --git a/Sources/Fetching and Querying/Concrete Clauses/GroupBy.swift b/Sources/Fetching and Querying/Concrete Clauses/GroupBy.swift index facc0b6..561635d 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/GroupBy.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/GroupBy.swift @@ -74,7 +74,7 @@ public struct GroupBy: QueryClause, Hashable { CoreStore.log( .Warning, - message: "An existing \"propertiesToGroupBy\" for the \(typeName(NSFetchRequest)) was overwritten by \(typeName(self)) query clause." + message: "An existing \"propertiesToGroupBy\" for the \(cs_typeName(NSFetchRequest)) was overwritten by \(cs_typeName(self)) query clause." ) } diff --git a/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift b/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift index 6ebd02e..5db68a2 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift @@ -141,7 +141,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { CoreStore.log( .Warning, - message: "Existing sortDescriptors for the \(typeName(NSFetchRequest)) was overwritten by \(typeName(self)) query clause." + message: "Existing sortDescriptors for the \(cs_typeName(NSFetchRequest)) was overwritten by \(cs_typeName(self)) query clause." ) } diff --git a/Sources/Fetching and Querying/Concrete Clauses/Select.swift b/Sources/Fetching and Querying/Concrete Clauses/Select.swift index 20c9146..a5eb12f 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/Select.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/Select.swift @@ -722,7 +722,7 @@ internal extension CollectionType where Generator.Element == SelectTerm { CoreStore.log( .Warning, - message: "The property \"\(keyPath)\" does not exist in entity \(typeName(entityDescription.managedObjectClassName)) and will be ignored by \(typeName(owner)) query clause." + message: "The property \"\(keyPath)\" does not exist in entity \(cs_typeName(entityDescription.managedObjectClassName)) and will be ignored by \(cs_typeName(owner)) query clause." ) } @@ -750,7 +750,7 @@ internal extension CollectionType where Generator.Element == SelectTerm { CoreStore.log( .Warning, - message: "The attribute \"\(keyPath)\" does not exist in entity \(typeName(entityDescription.managedObjectClassName)) and will be ignored by \(typeName(owner)) query clause." + message: "The attribute \"\(keyPath)\" does not exist in entity \(cs_typeName(entityDescription.managedObjectClassName)) and will be ignored by \(cs_typeName(owner)) query clause." ) } diff --git a/Sources/Fetching and Querying/Concrete Clauses/Where.swift b/Sources/Fetching and Querying/Concrete Clauses/Where.swift index 4d7a20f..18677a6 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/Where.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/Where.swift @@ -146,7 +146,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { CoreStore.log( .Warning, - message: "An existing predicate for the \(typeName(NSFetchRequest)) was overwritten by \(typeName(self)) query clause." + message: "An existing predicate for the \(cs_typeName(NSFetchRequest)) was overwritten by \(cs_typeName(self)) query clause." ) } diff --git a/Sources/Fetching and Querying/DataStack+Querying.swift b/Sources/Fetching and Querying/DataStack+Querying.swift index 4cd93d7..9f13947 100644 --- a/Sources/Fetching and Querying/DataStack+Querying.swift +++ b/Sources/Fetching and Querying/DataStack+Querying.swift @@ -108,7 +108,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchOne(from, fetchClauses) } @@ -125,7 +125,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchOne(from, fetchClauses) } @@ -142,7 +142,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchAll(from, fetchClauses) } @@ -159,7 +159,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchAll(from, fetchClauses) } @@ -176,7 +176,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchCount(from, fetchClauses) } @@ -193,7 +193,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchCount(from, fetchClauses) } @@ -210,7 +210,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchObjectID(from, fetchClauses) } @@ -227,7 +227,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchObjectID(from, fetchClauses) } @@ -244,7 +244,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchObjectIDs(from, fetchClauses) } @@ -261,7 +261,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.fetchObjectIDs(from, fetchClauses) } @@ -281,7 +281,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to query from a \(typeName(self)) outside the main thread." + "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.queryValue(from, selectClause, queryClauses) } @@ -301,7 +301,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to query from a \(typeName(self)) outside the main thread." + "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.queryValue(from, selectClause, queryClauses) } @@ -321,7 +321,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to query from a \(typeName(self)) outside the main thread." + "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.queryAttributes(from, selectClause, queryClauses) } @@ -341,7 +341,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to query from a \(typeName(self)) outside the main thread." + "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) return self.mainContext.queryAttributes(from, selectClause, queryClauses) } diff --git a/Sources/Importing/BaseDataTransaction+Importing.swift b/Sources/Importing/BaseDataTransaction+Importing.swift index 3212ea7..1c6a431 100644 --- a/Sources/Importing/BaseDataTransaction+Importing.swift +++ b/Sources/Importing/BaseDataTransaction+Importing.swift @@ -44,10 +44,10 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue." + "Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue." ) - return try autoreleasepool { + return try cs_autoreleasepool { guard T.shouldInsertFromImportSource(source, inTransaction: self) else { @@ -72,10 +72,10 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(typeName(object)) outside the transaction's designated queue." + "Attempted to import an object of type \(cs_typeName(object)) outside the transaction's designated queue." ) - try autoreleasepool { + try cs_autoreleasepool { guard T.shouldInsertFromImportSource(source, inTransaction: self) else { @@ -99,10 +99,10 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue." + "Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue." ) - return try autoreleasepool { + return try cs_autoreleasepool { return try sourceArray.flatMap { (source) -> T? in @@ -111,7 +111,7 @@ public extension BaseDataTransaction { return nil } - return try autoreleasepool { + return try cs_autoreleasepool { let object = self.create(into) try object.didInsertFromImportSource(source, inTransaction: self) @@ -134,10 +134,10 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue." + "Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue." ) - return try autoreleasepool { + return try cs_autoreleasepool { let uniqueIDKeyPath = T.uniqueIDKeyPath guard let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) else { @@ -185,13 +185,13 @@ public extension BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue." + "Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue." ) - return try autoreleasepool { + return try cs_autoreleasepool { var mapping = Dictionary() - let sortedIDs = try autoreleasepool { + let sortedIDs = try cs_autoreleasepool { return try sourceArray.flatMap { (source) -> T.UniqueIDType? in @@ -205,12 +205,12 @@ public extension BaseDataTransaction { } } - mapping = try autoreleasepool { try preProcess(mapping: mapping) } + mapping = try cs_autoreleasepool { try preProcess(mapping: mapping) } var objects = Dictionary() for object in self.fetchAll(From(T), Where(T.uniqueIDKeyPath, isMemberOf: mapping.keys)) ?? [] { - try autoreleasepool { + try cs_autoreleasepool { let uniqueIDValue = object.uniqueIDValue @@ -227,7 +227,7 @@ public extension BaseDataTransaction { for (uniqueIDValue, source) in mapping { - try autoreleasepool { + try cs_autoreleasepool { guard T.shouldInsertFromImportSource(source, inTransaction: self) else { diff --git a/Sources/Internal/AssociatedObjects.swift b/Sources/Internal/AssociatedObjects.swift deleted file mode 100644 index a5c119a..0000000 --- a/Sources/Internal/AssociatedObjects.swift +++ /dev/null @@ -1,68 +0,0 @@ -// -// NSObject+CoreStore.swift -// CoreStore -// -// Copyright © 2014 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 - -internal func getAssociatedObjectForKey(key: UnsafePointer, inObject object: AnyObject) -> 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 - } -} - -internal func setAssociatedRetainedObject(associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { - - objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) -} - -internal func setAssociatedCopiedObject(associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { - - objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_COPY_NONATOMIC) -} - -internal func setAssociatedAssignedObject(associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { - - objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_ASSIGN) -} - -internal func setAssociatedWeakObject(associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { - - if let associatedObject = associatedObject { - - objc_setAssociatedObject(object, key, WeakObject(associatedObject), .OBJC_ASSOCIATION_RETAIN_NONATOMIC) - } - else { - - objc_setAssociatedObject(object, key, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) - } -} diff --git a/Sources/Internal/CoreStoreFetchRequest.swift b/Sources/Internal/CoreStoreFetchRequest.swift index e3bce41..635d111 100644 --- a/Sources/Internal/CoreStoreFetchRequest.swift +++ b/Sources/Internal/CoreStoreFetchRequest.swift @@ -39,5 +39,6 @@ internal final class CoreStoreFetchRequest: NSFetchRequest { set { self.safeAffectedStores = newValue } } + @nonobjc private var safeAffectedStores: [NSPersistentStore]? } diff --git a/Sources/Internal/CoreStoreFetchedResultsController.swift b/Sources/Internal/CoreStoreFetchedResultsController.swift index f76eb37..bc35a1d 100644 --- a/Sources/Internal/CoreStoreFetchedResultsController.swift +++ b/Sources/Internal/CoreStoreFetchedResultsController.swift @@ -34,6 +34,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll // MARK: Internal + @nonobjc internal convenience init(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) { self.init( @@ -45,6 +46,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll ) } + @nonobjc internal init(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) { from?.applyToFetchRequest(fetchRequest, context: context, applyAffectedStores: false) @@ -61,7 +63,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll guard let from = (fetchRequest.entity.flatMap { $0.managedObjectClassName }).flatMap(NSClassFromString).flatMap(From.init) else { - fatalError("Attempted to create an \(typeName(NSFetchedResultsController)) without a From clause or an NSEntityDescription.") + fatalError("Attempted to create an \(cs_typeName(NSFetchedResultsController)) without a From clause or an NSEntityDescription.") } self.reapplyAffectedStores = { fetchRequest, context in @@ -78,13 +80,14 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll ) } + @nonobjc internal func performFetchFromSpecifiedStores() throws { if !self.reapplyAffectedStores(fetchRequest: self.fetchRequest, context: self.managedObjectContext) { CoreStore.log( .Warning, - message: "Attempted to perform a fetch on an \(typeName(NSFetchedResultsController)) but could not find any persistent store for the entity \(typeName(self.fetchRequest.entityName))" + message: "Attempted to perform a fetch on an \(cs_typeName(NSFetchedResultsController)) but could not find any persistent store for the entity \(cs_typeName(self.fetchRequest.entityName))" ) } try self.performFetch() @@ -98,5 +101,6 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll // MARK: Private + @nonobjc private let reapplyAffectedStores: (fetchRequest: NSFetchRequest, context: NSManagedObjectContext) -> Bool } diff --git a/Sources/Internal/FetchedResultsControllerDelegate.swift b/Sources/Internal/FetchedResultsControllerDelegate.swift index 9f34b6e..ee43b05 100644 --- a/Sources/Internal/FetchedResultsControllerDelegate.swift +++ b/Sources/Internal/FetchedResultsControllerDelegate.swift @@ -51,9 +51,13 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult // MARK: Internal + @nonobjc internal var enabled = true + @nonobjc internal weak var handler: FetchedResultsControllerHandler? + + @nonobjc internal weak var fetchedResultsController: NSFetchedResultsController? { didSet { @@ -71,7 +75,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult // MARK: NSFetchedResultsControllerDelegate - @objc dynamic func controllerWillChangeContent(controller: NSFetchedResultsController) { + @objc + dynamic func controllerWillChangeContent(controller: NSFetchedResultsController) { guard self.enabled else { @@ -84,7 +89,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult self.handler?.controllerWillChangeContent(controller) } - @objc dynamic func controllerDidChangeContent(controller: NSFetchedResultsController) { + @objc + dynamic func controllerDidChangeContent(controller: NSFetchedResultsController) { guard self.enabled else { @@ -94,7 +100,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult self.handler?.controllerDidChangeContent(controller) } - @objc dynamic func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) { + @objc + dynamic func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) { guard self.enabled else { @@ -181,7 +188,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult ) } - @objc dynamic func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) { + @objc + dynamic func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) { guard self.enabled else { @@ -203,7 +211,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult ) } - @objc dynamic func controller(controller: NSFetchedResultsController, sectionIndexTitleForSectionName sectionName: String) -> String? { + @objc + dynamic func controller(controller: NSFetchedResultsController, sectionIndexTitleForSectionName sectionName: String) -> String? { return self.handler?.controller( controller, @@ -214,6 +223,9 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult // MARK: Private + @nonobjc private var deletedSections = Set() + + @nonobjc private var insertedSections = Set() } diff --git a/Sources/Internal/Functions.swift b/Sources/Internal/Functions.swift index 9cb7276..ce944de 100644 --- a/Sources/Internal/Functions.swift +++ b/Sources/Internal/Functions.swift @@ -25,10 +25,18 @@ import Foundation -internal func autoreleasepool(@noescape closure: () -> T) -> T { + +// MARK: - Custom AutoreleasePool + +internal func cs_autoreleasepool(@noescape closure: () -> Void) { + + autoreleasepool(closure) +} + +internal func cs_autoreleasepool(@noescape closure: () -> T) -> T { var closureValue: T! - ObjectiveC.autoreleasepool { + autoreleasepool { closureValue = closure() } @@ -36,11 +44,11 @@ internal func autoreleasepool(@noescape closure: () -> T) -> T { return closureValue } -internal func autoreleasepool(@noescape closure: () throws -> T) throws -> T { +internal func cs_autoreleasepool(@noescape closure: () throws -> T) throws -> T { var closureValue: T! var closureError: ErrorType? - ObjectiveC.autoreleasepool { + autoreleasepool { do { @@ -59,10 +67,10 @@ internal func autoreleasepool(@noescape closure: () throws -> T) throws -> T return closureValue } -internal func autoreleasepool(@noescape closure: () throws -> Void) throws { +internal func cs_autoreleasepool(@noescape closure: () throws -> Void) throws { var closureError: ErrorType? - ObjectiveC.autoreleasepool { + autoreleasepool { do { @@ -79,3 +87,63 @@ internal func autoreleasepool(@noescape closure: () throws -> Void) throws { throw closureError } } + +internal func cs_getAssociatedObjectForKey(key: UnsafePointer, inObject object: AnyObject) -> 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 + } +} + +internal func cs_setAssociatedRetainedObject(associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { + + objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) +} + +internal func cs_setAssociatedCopiedObject(associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { + + objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_COPY_NONATOMIC) +} + +internal func cs_setAssociatedWeakObject(associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { + + 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 + +internal func cs_typeName(value: T) -> String { + + return "'\(String(reflecting: value.dynamicType))'" +} + +internal func cs_typeName(value: T.Type) -> String { + + return "'\(value)'" +} + +internal func cs_typeName(value: AnyClass) -> String { + + return "'\(value)'" +} + +internal func cs_typeName(name: String?) -> String { + + return "<\(name ?? "unknown")>" +} diff --git a/Sources/Internal/NSManagedObjectContext+CoreStore.swift b/Sources/Internal/NSManagedObjectContext+CoreStore.swift index 7726840..8840947 100644 --- a/Sources/Internal/NSManagedObjectContext+CoreStore.swift +++ b/Sources/Internal/NSManagedObjectContext+CoreStore.swift @@ -41,7 +41,7 @@ internal extension NSManagedObjectContext { get { - let number: NSNumber? = getAssociatedObjectForKey( + let number: NSNumber? = cs_getAssociatedObjectForKey( &PropertyKeys.shouldCascadeSavesToParent, inObject: self ) @@ -49,7 +49,7 @@ internal extension NSManagedObjectContext { } set { - setAssociatedCopiedObject( + cs_setAssociatedCopiedObject( NSNumber(bool: newValue), forKey: &PropertyKeys.shouldCascadeSavesToParent, inObject: self @@ -132,14 +132,14 @@ internal extension NSManagedObjectContext { get { - return getAssociatedObjectForKey( + return cs_getAssociatedObjectForKey( &PropertyKeys.observerForWillSaveNotification, inObject: self ) } set { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( newValue, forKey: &PropertyKeys.observerForWillSaveNotification, inObject: self diff --git a/Sources/Internal/NSManagedObjectContext+Querying.swift b/Sources/Internal/NSManagedObjectContext+Querying.swift index a069ab1..d9bc0f3 100644 --- a/Sources/Internal/NSManagedObjectContext+Querying.swift +++ b/Sources/Internal/NSManagedObjectContext+Querying.swift @@ -64,7 +64,7 @@ internal extension NSManagedObjectContext { CoreStore.log( CoreStoreError(error), - "Failed to load existing \(typeName(object)) in context." + "Failed to load existing \(cs_typeName(object)) in context." ) return nil } @@ -341,7 +341,7 @@ internal extension NSManagedObjectContext { var fetchError: ErrorType? self.performBlockAndWait { - autoreleasepool { + cs_autoreleasepool { do { diff --git a/Sources/Internal/NSManagedObjectContext+Setup.swift b/Sources/Internal/NSManagedObjectContext+Setup.swift index 0e268d9..854eb0b 100644 --- a/Sources/Internal/NSManagedObjectContext+Setup.swift +++ b/Sources/Internal/NSManagedObjectContext+Setup.swift @@ -43,7 +43,7 @@ internal extension NSManagedObjectContext { return parentContext.parentStack } - return getAssociatedObjectForKey(&PropertyKeys.parentStack, inObject: self) + return cs_getAssociatedObjectForKey(&PropertyKeys.parentStack, inObject: self) } set { @@ -52,7 +52,7 @@ internal extension NSManagedObjectContext { return } - setAssociatedWeakObject( + cs_setAssociatedWeakObject( newValue, forKey: &PropertyKeys.parentStack, inObject: self @@ -129,14 +129,14 @@ internal extension NSManagedObjectContext { get { - return getAssociatedObjectForKey( + return cs_getAssociatedObjectForKey( &PropertyKeys.observerForDidSaveNotification, inObject: self ) } set { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( newValue, forKey: &PropertyKeys.observerForDidSaveNotification, inObject: self @@ -149,14 +149,14 @@ internal extension NSManagedObjectContext { get { - return getAssociatedObjectForKey( + return cs_getAssociatedObjectForKey( &PropertyKeys.observerForDidImportUbiquitousContentChangesNotification, inObject: self ) } set { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( newValue, forKey: &PropertyKeys.observerForDidImportUbiquitousContentChangesNotification, inObject: self diff --git a/Sources/Internal/NSManagedObjectContext+Transaction.swift b/Sources/Internal/NSManagedObjectContext+Transaction.swift index dd5d8bb..89cb583 100644 --- a/Sources/Internal/NSManagedObjectContext+Transaction.swift +++ b/Sources/Internal/NSManagedObjectContext+Transaction.swift @@ -41,14 +41,14 @@ internal extension NSManagedObjectContext { get { - return getAssociatedObjectForKey( + return cs_getAssociatedObjectForKey( &PropertyKeys.parentTransaction, inObject: self ) } set { - setAssociatedWeakObject( + cs_setAssociatedWeakObject( newValue, forKey: &PropertyKeys.parentTransaction, inObject: self @@ -100,7 +100,7 @@ internal extension NSManagedObjectContext { let saveError = CoreStoreError(error) CoreStore.log( saveError, - "Failed to save \(typeName(NSManagedObjectContext))." + "Failed to save \(cs_typeName(NSManagedObjectContext))." ) result = SaveResult(saveError) return @@ -149,7 +149,7 @@ internal extension NSManagedObjectContext { let saveError = CoreStoreError(error) CoreStore.log( saveError, - "Failed to save \(typeName(NSManagedObjectContext))." + "Failed to save \(cs_typeName(NSManagedObjectContext))." ) GCDQueue.Main.async { diff --git a/Sources/Internal/NSManagedObjectModel+Setup.swift b/Sources/Internal/NSManagedObjectModel+Setup.swift index ac9d8d5..6ceb1da 100644 --- a/Sources/Internal/NSManagedObjectModel+Setup.swift +++ b/Sources/Internal/NSManagedObjectModel+Setup.swift @@ -47,7 +47,7 @@ internal extension NSManagedObjectModel { guard let versionInfo = NSDictionary(contentsOfURL: versionInfoPlistURL), let versionHashes = versionInfo["NSManagedObjectModel_VersionHashes"] as? [String: AnyObject] else { - fatalError("Could not load \(typeName(NSManagedObjectModel)) metadata from path \"\(versionInfoPlistURL)\".") + fatalError("Could not load \(cs_typeName(NSManagedObjectModel)) metadata from path \"\(versionInfoPlistURL)\".") } let modelVersions = Set(versionHashes.keys) @@ -106,7 +106,7 @@ internal extension NSManagedObjectModel { return rootModel } - fatalError("Could not create an \(typeName(NSManagedObjectModel)) from the model at URL \"\(modelFileURL)\".") + fatalError("Could not create an \(cs_typeName(NSManagedObjectModel)) from the model at URL \"\(modelFileURL)\".") } @nonobjc @@ -114,7 +114,7 @@ internal extension NSManagedObjectModel { get { - let value: NSString? = getAssociatedObjectForKey( + let value: NSString? = cs_getAssociatedObjectForKey( &PropertyKeys.currentModelVersion, inObject: self ) @@ -122,7 +122,7 @@ internal extension NSManagedObjectModel { } set { - setAssociatedCopiedObject( + cs_setAssociatedCopiedObject( newValue == nil ? nil : (newValue! as NSString), forKey: &PropertyKeys.currentModelVersion, inObject: self @@ -135,7 +135,7 @@ internal extension NSManagedObjectModel { get { - let value: NSSet? = getAssociatedObjectForKey( + let value: NSSet? = cs_getAssociatedObjectForKey( &PropertyKeys.modelVersions, inObject: self ) @@ -143,7 +143,7 @@ internal extension NSManagedObjectModel { } set { - setAssociatedCopiedObject( + cs_setAssociatedCopiedObject( newValue == nil ? nil : (newValue! as NSSet), forKey: &PropertyKeys.modelVersions, inObject: self @@ -235,7 +235,7 @@ internal extension NSManagedObjectModel { get { - let value: NSURL? = getAssociatedObjectForKey( + let value: NSURL? = cs_getAssociatedObjectForKey( &PropertyKeys.modelVersionFileURL, inObject: self ) @@ -243,7 +243,7 @@ internal extension NSManagedObjectModel { } set { - setAssociatedCopiedObject( + cs_setAssociatedCopiedObject( newValue, forKey: &PropertyKeys.modelVersionFileURL, inObject: self @@ -256,7 +256,7 @@ internal extension NSManagedObjectModel { get { - if let mapping: NSDictionary = getAssociatedObjectForKey(&PropertyKeys.entityNameMapping, inObject: self) { + if let mapping: NSDictionary = cs_getAssociatedObjectForKey(&PropertyKeys.entityNameMapping, inObject: self) { return mapping as! [String: String] } @@ -272,7 +272,7 @@ internal extension NSManagedObjectModel { let className = $0.managedObjectClassName mapping[className] = entityName } - setAssociatedCopiedObject( + cs_setAssociatedCopiedObject( mapping as NSDictionary, forKey: &PropertyKeys.entityNameMapping, inObject: self diff --git a/Sources/Internal/NSPersistentStore+Setup.swift b/Sources/Internal/NSPersistentStore+Setup.swift index 78da0da..4137819 100644 --- a/Sources/Internal/NSPersistentStore+Setup.swift +++ b/Sources/Internal/NSPersistentStore+Setup.swift @@ -38,7 +38,7 @@ internal extension NSPersistentStore { get { - let wrapper: StorageObject? = getAssociatedObjectForKey( + let wrapper: StorageObject? = cs_getAssociatedObjectForKey( &PropertyKeys.storageInterface, inObject: self ) @@ -46,7 +46,7 @@ internal extension NSPersistentStore { } set { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( StorageObject(newValue), forKey: &PropertyKeys.storageInterface, inObject: self @@ -70,8 +70,10 @@ private class StorageObject: NSObject { // MARK: Private + @nonobjc private let storageInterface: StorageInterface? + @nonobjc private init(_ storage: StorageInterface?) { self.storageInterface = storage diff --git a/Sources/Internal/NSPersistentStoreCoordinator+Setup.swift b/Sources/Internal/NSPersistentStoreCoordinator+Setup.swift index fe84725..f59507b 100644 --- a/Sources/Internal/NSPersistentStoreCoordinator+Setup.swift +++ b/Sources/Internal/NSPersistentStoreCoordinator+Setup.swift @@ -81,7 +81,7 @@ internal extension NSPersistentStoreCoordinator { else { self.lock() - autoreleasepool { + cs_autoreleasepool { result = closure() } @@ -129,7 +129,7 @@ internal extension NSPersistentStoreCoordinator { else { self.lock() - autoreleasepool { + cs_autoreleasepool { do { diff --git a/Sources/Logging/CoreStore+CustomDebugStringConvertible.swift b/Sources/Logging/CoreStore+CustomDebugStringConvertible.swift new file mode 100644 index 0000000..d10d781 --- /dev/null +++ b/Sources/Logging/CoreStore+CustomDebugStringConvertible.swift @@ -0,0 +1,409 @@ +// +// CoreStore+CustomDebugStringConvertible.swift +// CoreStore +// +// Copyright © 2016 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: - CoreStoreError + +extension CoreStoreError: CustomDebugStringConvertible, IndentableDebugStringConvertible { + + // MARK: CustomDebugStringConvertible + + public var debugDescription: String { + + return self.cs_dump() + } + + + // MARK: IndentableDebugStringConvertible + + private var cs_dumpValue: String { + + switch self { + + case .Unknown: return ".Unknown" + case .DifferentStorageExistsAtURL: return ".DifferentStorageExistsAtURL" + case .MappingModelNotFound: return ".MappingModelNotFound" + case .ProgressiveMigrationRequired: return ".ProgressiveMigrationRequired" + case .InternalError: return ".InternalError" + } + } + + private var cs_dumpInfo: DumpInfo { + + var info: DumpInfo = [ + ("_domain", self._domain.cs_dump()), + ("_code", self._code.cs_dump()), + ] + switch self { + + case .Unknown: + break + + case .DifferentStorageExistsAtURL(let existingPersistentStoreURL): + info.append(("existingPersistentStoreURL", existingPersistentStoreURL.cs_dump())) + + case .MappingModelNotFound(let localStoreURL, let targetModel, let targetModelVersion): + info.append(("localStoreURL", localStoreURL.cs_dump())) + info.append(("targetModel", targetModel.cs_dump())) + info.append(("targetModelVersion", targetModelVersion.cs_dump())) + + case .ProgressiveMigrationRequired(let localStoreURL): + info.append(("localStoreURL", localStoreURL.cs_dump())) + + case .InternalError(let NSError): + info.append(("NSError", NSError.cs_dump())) + } + return info + } +} + + +// MARK: - InMemoryStore + +extension InMemoryStore: CustomDebugStringConvertible, IndentableDebugStringConvertible { + + // MARK: CustomDebugStringConvertible + + public var debugDescription: String { + + return self.cs_dump() + } + + + // MARK: IndentableDebugStringConvertible + + private var cs_dumpInfo: DumpInfo { + + return [ + ("configuration", self.configuration), + ("storeOptions", self.storeOptions) + ] + } +} + + +// MARK: - LocalStorageOptions + +extension LocalStorageOptions: CustomDebugStringConvertible, IndentableDebugStringConvertible { + + // MARK: CustomDebugStringConvertible + + public var debugDescription: String { + + return self.cs_dump() + } + + + // MARK: IndentableDebugStringConvertible + + private var cs_dumpValue: String { + + var flags = [String]() + if self.contains(.RecreateStoreOnModelMismatch) { + + flags.append(".RecreateStoreOnModelMismatch") + } + if self.contains(.PreventProgressiveMigration) { + + flags.append(".PreventProgressiveMigration") + } + if self.contains(.AllowSynchronousLightweightMigration) { + + flags.append(".AllowSynchronousLightweightMigration") + } + switch flags.count { + + case 0: + return "[.None]" + + case 1: + return "[.\(flags[0])]" + + default: + let description = "[\n" + flags.joinWithSeparator(",\n") + return description.indent(1) + "\n]" + } + } +} + + +// MARK: - SQLiteStore + +extension SQLiteStore: CustomDebugStringConvertible, IndentableDebugStringConvertible { + + // MARK: CustomDebugStringConvertible + + public var debugDescription: String { + + return self.cs_dump() + } + + + // MARK: IndentableDebugStringConvertible + + private var cs_dumpInfo: DumpInfo { + + return [ + ("configuration", self.configuration), + ("storeOptions", self.storeOptions), + ("fileURL", self.fileURL), + ("mappingModelBundles", self.mappingModelBundles), + ("localStorageOptions", self.localStorageOptions) + ] + } +} + + +// MARK: - LegacySQLiteStore + +extension LegacySQLiteStore: CustomDebugStringConvertible, IndentableDebugStringConvertible { + + // MARK: CustomDebugStringConvertible + + public var debugDescription: String { + + return self.cs_dump() + } + + + // MARK: IndentableDebugStringConvertible + + private var cs_dumpInfo: DumpInfo { + + return [ + ("configuration", self.configuration), + ("storeOptions", self.storeOptions), + ("fileURL", self.fileURL), + ("mappingModelBundles", self.mappingModelBundles), + ("localStorageOptions", self.localStorageOptions) + ] + } +} + + +// MARK: - Private + +private typealias DumpInfo = [(key: String, value: IndentableDebugStringConvertible)] + +private func formattedValue(any: Any) -> String { + + if let any = any as? IndentableDebugStringConvertible { + + return formattedValue(any) + } + return "\(any)" +} + +private func formattedValue(any: IndentableDebugStringConvertible) -> String { + + return any.cs_dumpValue +} + +private protocol IndentableDebugStringConvertible { + + static func cs_typeString() -> String + + var cs_dumpValue: String { get } + var cs_dumpInfo: DumpInfo { get } + + func cs_dump() -> String +} + +private extension IndentableDebugStringConvertible { + + private static func cs_typeString() -> String { + + return String(reflecting: self) + } + + private var cs_dumpValue: String { + + return "" + } + + private var cs_dumpInfo: DumpInfo { + + return [] + } + + private func cs_dump() -> String { + + let value = self.cs_dumpValue + let info = self.cs_dumpInfo + + var dump = "(\(self.dynamicType.cs_typeString()))" + if !value.isEmpty { + + dump.appendContentsOf(" \(value)") + } + if info.isEmpty { + + return dump + } + else { + + dump.appendContentsOf(" {") + for (key, value) in info { + + dump.appendContentsOf("\n.\(key) = \(formattedValue(value))") + } + return dump.indent(1) + "\n}" + } + } +} + +extension String: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + return "\"\(self)\"" + } +} + +extension NSURL: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + return "\"\(self)\"" + } +} + +extension Int: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + return "\(self)" + } +} + +extension NSManagedObjectModel: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + return "\(self)" + } +} + +extension NSMappingModel: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + return "\(self)" + } +} + +extension NSError: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + return "\(self)" + } +} + +extension NSBundle: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + return "\(self.bundleURL.lastPathComponent ?? "") (\(self.bundleIdentifier ?? ""))" + } +} + +extension Array: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + var string = "\(self.count) items [" + if self.isEmpty { + + string.appendContentsOf("]") + return string + } + else { + + for (index, item) in self.enumerate() { + + string.appendContentsOf("\n\(index) = \(formattedValue(item));") + } + return string.indent(1) + "\n]" + } + } +} + +extension Dictionary: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + var string = "\(self.count) key-values [" + if self.isEmpty { + + string.appendContentsOf("]") + return string + } + else { + + for (key, value) in self { + + string.appendContentsOf("\n\(formattedValue(key)) = \(formattedValue(value));") + } + return string.indent(1) + "\n]" + } + } +} + +extension Optional: IndentableDebugStringConvertible { + + private var cs_dumpValue: String { + + if let value = self { + + return formattedValue(value) + } + return "nil" + } +} + +private extension String { + + private static func indention(level: Int = 1) -> String { + + return String(count: level * 4, repeatedValue: Character(" ")) + } + + private func trimSwiftModuleName() -> String { + + if self.hasPrefix("Swift.") { + + return self.substringFromIndex("Swift.".endIndex) + } + return self + } + + private func indent(level: Int) -> String { + + return self.stringByReplacingOccurrencesOfString("\n", withString: "\n\(String.indention(level))") + } +} diff --git a/Sources/Logging/CoreStoreLogger.swift b/Sources/Logging/CoreStoreLogger.swift index 367bb57..ced31b4 100644 --- a/Sources/Logging/CoreStoreLogger.swift +++ b/Sources/Logging/CoreStoreLogger.swift @@ -101,26 +101,3 @@ extension CoreStoreLogger { self.log(error: error.bridgeToSwift, message: message, fileName: fileName, lineNumber: lineNumber, functionName: functionName) } } - - -// MARK: - Utilities - -internal func typeName(value: T) -> String { - - return "'\(String(reflecting: value.dynamicType))'" -} - -internal func typeName(value: T.Type) -> String { - - return "'\(value)'" -} - -internal func typeName(value: AnyClass) -> String { - - return "'\(value)'" -} - -internal func typeName(name: String?) -> String { - - return "<\(name ?? "unknown")>" -} diff --git a/Sources/Migrating/DataStack+Migration.swift b/Sources/Migrating/DataStack+Migration.swift index 1f66c75..f3d2433 100644 --- a/Sources/Migrating/DataStack+Migration.swift +++ b/Sources/Migrating/DataStack+Migration.swift @@ -104,7 +104,7 @@ public extension DataStack { let storeError = CoreStoreError(error) CoreStore.log( storeError, - "Failed to add \(typeName(storage)) to the stack." + "Failed to add \(cs_typeName(storage)) to the stack." ) GCDQueue.Main.async { @@ -160,7 +160,7 @@ public extension DataStack { let fileURL = storage.fileURL CoreStore.assert( fileURL.fileURL, - "The specified URL for the \(typeName(storage)) is invalid: \"\(fileURL)\"" + "The specified URL for the \(cs_typeName(storage)) is invalid: \"\(fileURL)\"" ) return self.coordinator.performSynchronously { @@ -189,7 +189,7 @@ public extension DataStack { let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: fileURL) CoreStore.log( error, - "Failed to add \(typeName(storage)) at \"\(fileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists." + "Failed to add \(cs_typeName(storage)) at \"\(fileURL)\" because a different \(cs_typeName(NSPersistentStore)) at that URL already exists." ) GCDQueue.Main.async { @@ -281,7 +281,7 @@ public extension DataStack { let storeError = CoreStoreError(error) CoreStore.log( storeError, - "Failed to load SQLite \(typeName(NSPersistentStore)) metadata." + "Failed to load SQLite \(cs_typeName(NSPersistentStore)) metadata." ) GCDQueue.Main.async { @@ -345,7 +345,7 @@ public extension DataStack { let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: cacheFileURL) CoreStore.log( error, - "Failed to add \(typeName(storage)) at \"\(cacheFileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists." + "Failed to add \(cs_typeName(storage)) at \"\(cacheFileURL)\" because a different \(cs_typeName(NSPersistentStore)) at that URL already exists." ) GCDQueue.Main.async { @@ -418,7 +418,7 @@ public extension DataStack { let storeError = CoreStoreError(error) CoreStore.log( storeError, - "Failed to load \(typeName(NSPersistentStore)) metadata." + "Failed to load \(cs_typeName(NSPersistentStore)) metadata." ) GCDQueue.Main.async { @@ -445,7 +445,7 @@ public extension DataStack { CoreStore.assert( self.persistentStoreForStorage(storage) == nil, - "Attempted to migrate an already added \(typeName(storage)) at URL \"\(fileURL)\"" + "Attempted to migrate an already added \(cs_typeName(storage)) at URL \"\(fileURL)\"" ) let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStoreOfType( @@ -464,7 +464,7 @@ public extension DataStack { let metadataError = CoreStoreError(error) CoreStore.log( metadataError, - "Failed to load \(typeName(storage)) metadata from URL \"\(fileURL)\"." + "Failed to load \(cs_typeName(storage)) metadata from URL \"\(fileURL)\"." ) throw metadataError } @@ -487,7 +487,7 @@ public extension DataStack { CoreStore.assert( self.persistentStoreForStorage(storage) == nil, - "Attempted to query required migrations for an already added \(typeName(storage)) at URL \"\(fileURL)\"" + "Attempted to query required migrations for an already added \(cs_typeName(storage)) at URL \"\(fileURL)\"" ) do { @@ -506,7 +506,7 @@ public extension DataStack { ) CoreStore.log( error, - "Failed to find migration steps from the \(typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\"." + "Failed to find migration steps from the \(cs_typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\"." ) throw error } @@ -516,7 +516,7 @@ public extension DataStack { let error = CoreStoreError.ProgressiveMigrationRequired(localStoreURL: fileURL) CoreStore.log( error, - "Failed to find migration mapping from the \(typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." + "Failed to find migration mapping from the \(cs_typeName(storage)) at URL \"\(fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." ) throw error } @@ -533,7 +533,7 @@ public extension DataStack { let metadataError = CoreStoreError(error) CoreStore.log( metadataError, - "Failed to load \(typeName(storage)) metadata from URL \"\(fileURL)\"." + "Failed to load \(cs_typeName(storage)) metadata from URL \"\(fileURL)\"." ) throw metadataError } @@ -554,7 +554,7 @@ public extension DataStack { ) CoreStore.log( error, - "Failed to find migration steps from \(typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.model)\"." + "Failed to find migration steps from \(cs_typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.model)\"." ) GCDQueue.Main.async { @@ -579,7 +579,7 @@ public extension DataStack { let error = CoreStoreError.ProgressiveMigrationRequired(localStoreURL: storage.fileURL) CoreStore.log( error, - "Failed to find migration mapping from the \(typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." + "Failed to find migration mapping from the \(cs_typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." ) GCDQueue.Main.async { @@ -611,7 +611,7 @@ public extension DataStack { return } - autoreleasepool { + cs_autoreleasepool { do { diff --git a/Sources/Migrating/MigrationChain.swift b/Sources/Migrating/MigrationChain.swift index 524e4b9..452037d 100644 --- a/Sources/Migrating/MigrationChain.swift +++ b/Sources/Migrating/MigrationChain.swift @@ -89,7 +89,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D */ public init(_ elements: T) { - CoreStore.assert(Set(elements).count == Array(elements).count, "\(typeName(MigrationChain))'s migration chain could not be created due to duplicate version strings.") + CoreStore.assert(Set(elements).count == Array(elements).count, "\(cs_typeName(MigrationChain))'s migration chain could not be created due to duplicate version strings.") var lastVersion: String? var versionTree = [String: String]() @@ -124,7 +124,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D return } - CoreStore.assert(false, "\(typeName(MigrationChain))'s migration chain could not be created due to ambiguous version paths.") + CoreStore.assert(false, "\(cs_typeName(MigrationChain))'s migration chain could not be created due to ambiguous version paths.") valid = false } @@ -142,7 +142,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D if checklist.contains(nextVersion) { - CoreStore.assert(false, "\(typeName(MigrationChain))'s migration chain could not be created due to looping version paths.") + CoreStore.assert(false, "\(cs_typeName(MigrationChain))'s migration chain could not be created due to looping version paths.") return true } diff --git a/Sources/ObjectiveC/CSBaseDataTransaction+Querying.swift b/Sources/ObjectiveC/CSBaseDataTransaction+Querying.swift index 233ce62..7819423 100644 --- a/Sources/ObjectiveC/CSBaseDataTransaction+Querying.swift +++ b/Sources/ObjectiveC/CSBaseDataTransaction+Querying.swift @@ -110,7 +110,7 @@ public extension CSBaseDataTransaction { CoreStore.assert( self.bridgeToSwift.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.bridgeToSwift.context.fetchOne(from, fetchClauses) } @@ -128,7 +128,7 @@ public extension CSBaseDataTransaction { CoreStore.assert( self.bridgeToSwift.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.bridgeToSwift.context.fetchAll(from, fetchClauses) } @@ -146,7 +146,7 @@ public extension CSBaseDataTransaction { CoreStore.assert( self.bridgeToSwift.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.bridgeToSwift.context.fetchCount(from, fetchClauses) } @@ -164,7 +164,7 @@ public extension CSBaseDataTransaction { CoreStore.assert( self.bridgeToSwift.isRunningInAllowedQueue(), - "Attempted to fetch from a \(typeName(self)) outside its designated queue." + "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) return self.bridgeToSwift.context.fetchObjectID(from, fetchClauses) } @@ -185,7 +185,7 @@ public extension CSBaseDataTransaction { CoreStore.assert( self.bridgeToSwift.isRunningInAllowedQueue(), - "Attempted to query from a \(typeName(self)) outside its designated queue." + "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) return self.bridgeToSwift.context.queryValue(from, selectClause, queryClauses) } @@ -206,7 +206,7 @@ public extension CSBaseDataTransaction { CoreStore.assert( self.bridgeToSwift.isRunningInAllowedQueue(), - "Attempted to query from a \(typeName(self)) outside its designated queue." + "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) return self.bridgeToSwift.context.queryAttributes(from, selectClause, queryClauses) } diff --git a/Sources/ObjectiveC/CSCoreStore+Migrating.swift b/Sources/ObjectiveC/CSCoreStore+Migrating.swift index 198ce92..d462452 100644 --- a/Sources/ObjectiveC/CSCoreStore+Migrating.swift +++ b/Sources/ObjectiveC/CSCoreStore+Migrating.swift @@ -47,12 +47,10 @@ public extension CSCoreStore { - parameter storage: the `CSInMemoryStore` instance - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `CSSetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a failure `CSSetupResult` result if an error occurs asynchronously. - - parameter error: the `NSError` pointer that indicates the reason in case of an failure - - returns: an `NSProgress` instance if a migration has started. `nil` if no migrations are required or if `error` was set. */ - public static func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void, error: NSErrorPointer) -> NSProgress? { + public static func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void) { - return self.defaultStack.addInMemoryStorage(storage, completion: completion, error: error) + self.defaultStack.addInMemoryStorage(storage, completion: completion) } /** diff --git a/Sources/ObjectiveC/CSDataStack+Migrating.swift b/Sources/ObjectiveC/CSDataStack+Migrating.swift index c899c83..f47481b 100644 --- a/Sources/ObjectiveC/CSDataStack+Migrating.swift +++ b/Sources/ObjectiveC/CSDataStack+Migrating.swift @@ -47,19 +47,14 @@ public extension CSDataStack { - parameter storage: the `CSInMemoryStore` instance - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `CSSetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a failure `CSSetupResult` result if an error occurs asynchronously. - - parameter error: the `NSError` pointer that indicates the reason in case of an failure - - returns: an `NSProgress` instance if a migration has started. `nil` if no migrations are required or if `error` was set. */ @objc - public func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void, error: NSErrorPointer) -> NSProgress? { + public func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void) { - return bridge(error) { - - try self.bridgeToSwift.addStorage( - storage.bridgeToSwift, - completion: { completion($0.bridgeToObjectiveC) } - ) - } + self.bridgeToSwift.addStorage( + storage.bridgeToSwift, + completion: { completion($0.bridgeToObjectiveC) } + ) } /** diff --git a/Sources/ObjectiveC/CSDataStack+Observing.swift b/Sources/ObjectiveC/CSDataStack+Observing.swift index 7ae3496..9a4f045 100644 --- a/Sources/ObjectiveC/CSDataStack+Observing.swift +++ b/Sources/ObjectiveC/CSDataStack+Observing.swift @@ -61,7 +61,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) CoreStore.assert( fetchClauses.contains { $0 is CSOrderBy }, @@ -93,7 +93,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) CoreStore.assert( fetchClauses.contains { $0 is CSOrderBy }, @@ -128,7 +128,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) CoreStore.assert( fetchClauses.contains { $0 is CSOrderBy }, @@ -160,7 +160,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) CoreStore.assert( fetchClauses.contains { $0 is CSOrderBy }, diff --git a/Sources/ObjectiveC/CSDataStack+Querying.swift b/Sources/ObjectiveC/CSDataStack+Querying.swift index 3d68ad4..9e70e39 100644 --- a/Sources/ObjectiveC/CSDataStack+Querying.swift +++ b/Sources/ObjectiveC/CSDataStack+Querying.swift @@ -110,7 +110,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.bridgeToSwift.mainContext.fetchOne(from, fetchClauses) } @@ -128,7 +128,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.bridgeToSwift.mainContext.fetchAll(from, fetchClauses) } @@ -146,7 +146,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.bridgeToSwift.mainContext.fetchCount(from, fetchClauses) } @@ -164,7 +164,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.bridgeToSwift.mainContext.fetchObjectID(from, fetchClauses) } @@ -182,7 +182,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to fetch from a \(typeName(self)) outside the main thread." + "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) return self.bridgeToSwift.mainContext.fetchObjectIDs(from, fetchClauses) } @@ -203,7 +203,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to query from a \(typeName(self)) outside the main thread." + "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) return self.bridgeToSwift.mainContext.queryValue(from, selectClause, queryClauses) } @@ -224,7 +224,7 @@ public extension CSDataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to query from a \(typeName(self)) outside the main thread." + "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) return self.bridgeToSwift.mainContext.queryAttributes(from, selectClause, queryClauses) } diff --git a/Sources/Observing/DataStack+Observing.swift b/Sources/Observing/DataStack+Observing.swift index 8bae7f7..6517715 100644 --- a/Sources/Observing/DataStack+Observing.swift +++ b/Sources/Observing/DataStack+Observing.swift @@ -46,7 +46,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) return ObjectMonitor(dataStack: self, object: object) } @@ -76,7 +76,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) CoreStore.assert( fetchClauses.contains { $0 is OrderBy }, @@ -116,7 +116,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) CoreStore.assert( fetchClauses.contains { $0 is OrderBy }, @@ -161,7 +161,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) CoreStore.assert( fetchClauses.contains { $0 is OrderBy }, @@ -204,7 +204,7 @@ public extension DataStack { CoreStore.assert( NSThread.isMainThread(), - "Attempted to observe objects from \(typeName(self)) outside the main thread." + "Attempted to observe objects from \(cs_typeName(self)) outside the main thread." ) CoreStore.assert( fetchClauses.contains { $0 is OrderBy }, diff --git a/Sources/Observing/ListMonitor.swift b/Sources/Observing/ListMonitor.swift index f5c5cb8..7023ae1 100644 --- a/Sources/Observing/ListMonitor.swift +++ b/Sources/Observing/ListMonitor.swift @@ -119,7 +119,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) guard let sections = self.fetchedResultsController.sections @@ -146,7 +146,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.objectAtIndexPath(indexPath) as! T @@ -199,7 +199,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return (self.fetchedResultsController.fetchedObjects as? [T]) ?? [] @@ -216,7 +216,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return (self.fetchedResultsController.sections?[section].objects as? [T]) ?? [] @@ -233,7 +233,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return (self.fetchedResultsController.sections?[section].objects as? [T]) ?? [] @@ -249,7 +249,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sections?.count ?? 0 @@ -265,7 +265,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.fetchedObjects?.count ?? 0 @@ -306,7 +306,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sections![section] @@ -323,7 +323,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) guard let sections = self.fetchedResultsController.sections @@ -345,7 +345,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sections ?? [] @@ -363,7 +363,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sectionForSectionIndexTitle(title, atIndex: index) @@ -379,7 +379,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.sectionIndexTitles @@ -396,7 +396,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return (self.fetchedResultsController.fetchedObjects as? [T] ?? []).indexOf(object) @@ -413,7 +413,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( !self.isPendingRefetch || NSThread.isMainThread(), - "Attempted to access a \(typeName(self)) outside the main thread while a refetch is in progress." + "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) return self.fetchedResultsController.indexPathForObject(object) @@ -689,7 +689,7 @@ public final class ListMonitor: Hashable { internal func registerChangeNotification(notificationKey: UnsafePointer, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor) -> Void) { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( NotificationObserver( notificationName: name, object: self, @@ -709,7 +709,7 @@ public final class ListMonitor: Hashable { internal func registerObjectNotification(notificationKey: UnsafePointer, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor, object: T, indexPath: NSIndexPath?, newIndexPath: NSIndexPath?) -> Void) { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( NotificationObserver( notificationName: name, object: self, @@ -736,7 +736,7 @@ public final class ListMonitor: Hashable { internal func registerSectionNotification(notificationKey: UnsafePointer, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor, sectionInfo: NSFetchedResultsSectionInfo, sectionIndex: Int) -> Void) { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( NotificationObserver( notificationName: name, object: self, @@ -765,7 +765,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( NSThread.isMainThread(), - "Attempted to add an observer of type \(typeName(observer)) outside the main thread." + "Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread." ) self.registerChangeNotification( @@ -826,7 +826,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( NSThread.isMainThread(), - "Attempted to add an observer of type \(typeName(observer)) outside the main thread." + "Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread." ) self.registerObjectNotification( @@ -908,7 +908,7 @@ public final class ListMonitor: Hashable { CoreStore.assert( NSThread.isMainThread(), - "Attempted to add an observer of type \(typeName(observer)) outside the main thread." + "Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread." ) self.registerSectionNotification( @@ -953,29 +953,29 @@ public final class ListMonitor: Hashable { CoreStore.assert( NSThread.isMainThread(), - "Attempted to remove an observer of type \(typeName(observer)) outside the main thread." + "Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread." ) let nilValue: AnyObject? = nil - setAssociatedRetainedObject(nilValue, forKey: &self.willChangeListKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.didChangeListKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.willRefetchListKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.didRefetchListKey, inObject: observer) + 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) - setAssociatedRetainedObject(nilValue, forKey: &self.didInsertObjectKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.didMoveObjectKey, 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) - setAssociatedRetainedObject(nilValue, forKey: &self.didInsertSectionKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteSectionKey, inObject: observer) + cs_setAssociatedRetainedObject(nilValue, forKey: &self.didInsertSectionKey, inObject: observer) + cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteSectionKey, inObject: observer) } internal func refetch(applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) { CoreStore.assert( NSThread.isMainThread(), - "Attempted to refetch a \(typeName(self)) outside the main thread." + "Attempted to refetch a \(cs_typeName(self)) outside the main thread." ) if !self.isPendingRefetch { diff --git a/Sources/Observing/ObjectMonitor.swift b/Sources/Observing/ObjectMonitor.swift index d6dabf1..2914aac 100644 --- a/Sources/Observing/ObjectMonitor.swift +++ b/Sources/Observing/ObjectMonitor.swift @@ -129,7 +129,7 @@ public final class ObjectMonitor { CoreStore.assert( NSThread.isMainThread(), - "Attempted to add an observer of type \(typeName(observer)) outside the main thread." + "Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread." ) self.registerChangeNotification( &self.willChangeObjectKey, @@ -195,13 +195,13 @@ public final class ObjectMonitor { CoreStore.assert( NSThread.isMainThread(), - "Attempted to remove an observer of type \(typeName(observer)) outside the main thread." + "Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread." ) let nilValue: AnyObject? = nil - setAssociatedRetainedObject(nilValue, forKey: &self.willChangeObjectKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer) - setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer) + cs_setAssociatedRetainedObject(nilValue, forKey: &self.willChangeObjectKey, inObject: observer) + cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteObjectKey, inObject: observer) + cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer) } internal func upcast() -> ObjectMonitor { @@ -256,7 +256,7 @@ public final class ObjectMonitor { private func registerChangeNotification(notificationKey: UnsafePointer, name: String, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor) -> Void) { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( NotificationObserver( notificationName: name, object: self, @@ -276,7 +276,7 @@ public final class ObjectMonitor { private func registerObjectNotification(notificationKey: UnsafePointer, name: String, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor, object: T) -> Void) { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( NotificationObserver( notificationName: name, object: self, diff --git a/Sources/Setup/DataStack.swift b/Sources/Setup/DataStack.swift index cc672a0..5b0bd7c 100644 --- a/Sources/Setup/DataStack.swift +++ b/Sources/Setup/DataStack.swift @@ -64,7 +64,7 @@ public final class DataStack { CoreStore.assert( migrationChain.valid, - "Invalid migration chain passed to the \(typeName(DataStack)). Check that the model versions' order is correct and that no repetitions or ambiguities exist." + "Invalid migration chain passed to the \(cs_typeName(DataStack)). Check that the model versions' order is correct and that no repetitions or ambiguities exist." ) self.coordinator = NSPersistentStoreCoordinator(managedObjectModel: model) @@ -174,7 +174,7 @@ public final class DataStack { let storeError = CoreStoreError(error) CoreStore.log( storeError, - "Failed to add \(typeName(storage)) to the stack." + "Failed to add \(cs_typeName(storage)) to the stack." ) throw storeError } @@ -212,7 +212,7 @@ public final class DataStack { let fileURL = storage.fileURL CoreStore.assert( fileURL.fileURL, - "The specified store URL for the \"\(typeName(storage))\" is invalid: \"\(fileURL)\"" + "The specified store URL for the \"\(cs_typeName(storage))\" is invalid: \"\(fileURL)\"" ) if let _ = self.persistentStoreForStorage(storage) { @@ -231,7 +231,7 @@ public final class DataStack { let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: fileURL) CoreStore.log( error, - "Failed to add \(typeName(storage)) at \"\(fileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists." + "Failed to add \(cs_typeName(storage)) at \"\(fileURL)\" because a different \(cs_typeName(NSPersistentStore)) at that URL already exists." ) throw error } @@ -278,7 +278,7 @@ public final class DataStack { let storeError = CoreStoreError(error) CoreStore.log( storeError, - "Failed to add \(typeName(storage)) to the stack." + "Failed to add \(cs_typeName(storage)) to the stack." ) throw storeError } @@ -325,7 +325,7 @@ public final class DataStack { let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: cacheFileURL) CoreStore.log( error, - "Failed to add \(typeName(storage)) at \"\(cacheFileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists." + "Failed to add \(cs_typeName(storage)) at \"\(cacheFileURL)\" because a different \(cs_typeName(NSPersistentStore)) at that URL already exists." ) throw error } @@ -372,7 +372,7 @@ public final class DataStack { let storeError = CoreStoreError(error) CoreStore.log( storeError, - "Failed to add \(typeName(storage)) to the stack." + "Failed to add \(cs_typeName(storage)) to the stack." ) throw storeError } @@ -489,7 +489,7 @@ public final class DataStack { let managedObjectClassName = entityDescription.managedObjectClassName CoreStore.assert( NSClassFromString(managedObjectClassName) != nil, - "The class \(typeName(managedObjectClassName)) for the entity \(typeName(entityDescription.name)) does not exist. Check if the subclass type and module name are properly configured." + "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." ) if self.entityConfigurationsMapping[managedObjectClassName] == nil { diff --git a/Sources/Setup/StorageInterfaces/ICloudStore.swift b/Sources/Setup/StorageInterfaces/ICloudStore.swift index 57061fb..7512ddc 100644 --- a/Sources/Setup/StorageInterfaces/ICloudStore.swift +++ b/Sources/Setup/StorageInterfaces/ICloudStore.swift @@ -108,7 +108,7 @@ public class ICloudStore: CloudStorage { CoreStore.assert( NSThread.isMainThread(), - "Attempted to add an observer of type \(typeName(observer)) outside the main thread." + "Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread." ) self.removeObserver(observer) @@ -196,45 +196,45 @@ public class ICloudStore: CloudStorage { CoreStore.assert( NSThread.isMainThread(), - "Attempted to remove an observer of type \(typeName(observer)) outside the main thread." + "Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread." ) let nilValue: AnyObject? = nil - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &self.willFinishInitialImportKey, inObject: observer ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &self.didFinishInitialImportKey, inObject: observer ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &self.willAddAccountKey, inObject: observer ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &self.didAddAccountKey, inObject: observer ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &self.willRemoveAccountKey, inObject: observer ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &self.didRemoveAccountKey, inObject: observer ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &self.willRemoveContentKey, inObject: observer ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &self.didRemoveContentKey, inObject: observer @@ -272,7 +272,7 @@ public class ICloudStore: CloudStorage { self.dataStack = dataStack let coordinator = dataStack.coordinator - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( NotificationObserver( notificationName: NSPersistentStoreCoordinatorStoresWillChangeNotification, object: coordinator, @@ -314,7 +314,7 @@ public class ICloudStore: CloudStorage { forKey: &Static.persistentStoreCoordinatorWillChangeStores, inObject: self ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( NotificationObserver( notificationName: NSPersistentStoreCoordinatorStoresDidChangeNotification, object: coordinator, @@ -365,12 +365,12 @@ public class ICloudStore: CloudStorage { let coordinator = dataStack.coordinator let nilValue: AnyObject? = nil - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &Static.persistentStoreCoordinatorWillChangeStores, inObject: coordinator ) - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( nilValue, forKey: &Static.persistentStoreCoordinatorDidChangeStores, inObject: coordinator @@ -423,7 +423,7 @@ public class ICloudStore: CloudStorage { // TODO: check if attached to persistent store let cacheFileURL = self.cacheFileURL - try autoreleasepool { + try cs_autoreleasepool { let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel) let options = [ @@ -467,7 +467,7 @@ public class ICloudStore: CloudStorage { private func registerNotification(notificationKey: UnsafePointer, name: String, toObserver observer: T, callback: (observer: T, storage: ICloudStore, dataStack: DataStack) -> Void) { - setAssociatedRetainedObject( + cs_setAssociatedRetainedObject( NotificationObserver( notificationName: name, object: self, diff --git a/Sources/Setup/StorageInterfaces/ICloudStoreObserver.swift b/Sources/Setup/StorageInterfaces/ICloudStoreObserver.swift index ad56652..7c257cc 100644 --- a/Sources/Setup/StorageInterfaces/ICloudStoreObserver.swift +++ b/Sources/Setup/StorageInterfaces/ICloudStoreObserver.swift @@ -105,14 +105,18 @@ public protocol ICloudStoreObserver: class { public extension ICloudStoreObserver { public func iCloudStoreWillFinishUbiquitousStoreInitialImport(storage storage: ICloudStore, dataStack: DataStack) {} + public func iCloudStoreDidFinishUbiquitousStoreInitialImport(storage storage: ICloudStore, dataStack: DataStack) {} public func iCloudStoreWillAddAccount(storage storage: ICloudStore, dataStack: DataStack) {} + public func iCloudStoreDidAddAccount(storage storage: ICloudStore, dataStack: DataStack) {} public func iCloudStoreWillRemoveAccount(storage storage: ICloudStore, dataStack: DataStack) {} + public func iCloudStoreDidRemoveAccount(storage storage: ICloudStore, dataStack: DataStack) {} public func iCloudStoreWillRemoveContent(storage storage: ICloudStore, dataStack: DataStack) {} + public func iCloudStoreDidRemoveContent(storage storage: ICloudStore, dataStack: DataStack) {} } diff --git a/Sources/Setup/StorageInterfaces/LegacySQLiteStore.swift b/Sources/Setup/StorageInterfaces/LegacySQLiteStore.swift index 3d7b5af..a1fe0ce 100644 --- a/Sources/Setup/StorageInterfaces/LegacySQLiteStore.swift +++ b/Sources/Setup/StorageInterfaces/LegacySQLiteStore.swift @@ -169,7 +169,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore { // TODO: check if attached to persistent store let fileURL = self.fileURL - try autoreleasepool { + try cs_autoreleasepool { let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel) let store = try journalUpdatingCoordinator.addPersistentStoreWithType( diff --git a/Sources/Setup/StorageInterfaces/SQLiteStore.swift b/Sources/Setup/StorageInterfaces/SQLiteStore.swift index 11f9eef..9ca7498 100644 --- a/Sources/Setup/StorageInterfaces/SQLiteStore.swift +++ b/Sources/Setup/StorageInterfaces/SQLiteStore.swift @@ -167,7 +167,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore { // TODO: check if attached to persistent store let fileURL = self.fileURL - try autoreleasepool { + try cs_autoreleasepool { let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel) let store = try journalUpdatingCoordinator.addPersistentStoreWithType( diff --git a/Sources/Transactions/AsynchronousDataTransaction.swift b/Sources/Transactions/AsynchronousDataTransaction.swift index 607824a..f601634 100644 --- a/Sources/Transactions/AsynchronousDataTransaction.swift +++ b/Sources/Transactions/AsynchronousDataTransaction.swift @@ -46,11 +46,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to commit a \(typeName(self)) outside its designated queue." + "Attempted to commit a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to commit a \(typeName(self)) more than once." + "Attempted to commit a \(cs_typeName(self)) more than once." ) self.isCommitted = true @@ -75,11 +75,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to begin a child transaction from a \(typeName(self)) outside its designated queue." + "Attempted to begin a child transaction from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to begin a child transaction from an already committed \(typeName(self))." + "Attempted to begin a child transaction from an already committed \(cs_typeName(self))." ) return SynchronousDataTransaction( @@ -101,7 +101,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to create an entity of type \(typeName(T)) from an already committed \(typeName(self))." + "Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))." ) return super.create(into) @@ -118,7 +118,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to update an entity of type \(typeName(object)) from an already committed \(typeName(self))." + "Attempted to update an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))." ) return super.edit(object) @@ -136,7 +136,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to update an entity of type \(typeName(T)) from an already committed \(typeName(self))." + "Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))." ) return super.edit(into, objectID) @@ -151,7 +151,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to delete an entity of type \(typeName(object)) from an already committed \(typeName(self))." + "Attempted to delete an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))." ) super.delete(object) @@ -168,7 +168,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to delete an entities from an already committed \(typeName(self))." + "Attempted to delete an entities from an already committed \(cs_typeName(self))." ) super.delete(([object1, object2] + objects).flatMap { $0 }) @@ -183,7 +183,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to delete an entities from an already committed \(typeName(self))." + "Attempted to delete an entities from an already committed \(cs_typeName(self))." ) super.delete(objects) @@ -208,7 +208,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.log( .Warning, - message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded." + message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded." ) } } @@ -224,7 +224,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.log( .Warning, - message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded." + message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded." ) } } @@ -244,11 +244,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to rollback an already committed \(typeName(self))." + "Attempted to rollback an already committed \(cs_typeName(self))." ) CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to rollback a \(typeName(self)) outside its designated queue." + "Attempted to rollback a \(cs_typeName(self)) outside its designated queue." ) self.context.reset() diff --git a/Sources/Transactions/BaseDataTransaction.swift b/Sources/Transactions/BaseDataTransaction.swift index 0588e01..0b8f623 100644 --- a/Sources/Transactions/BaseDataTransaction.swift +++ b/Sources/Transactions/BaseDataTransaction.swift @@ -57,7 +57,7 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to create an entity of type \(typeName(T)) outside its designated queue." + "Attempted to create an entity of type \(cs_typeName(T)) outside its designated queue." ) let context = self.context @@ -72,10 +72,10 @@ public /*abstract*/ class BaseDataTransaction { return object case (nil, true): - fatalError("Attempted to create an entity of type \(typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.") + fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.") default: - fatalError("Attempted to create an entity of type \(typeName(entityClass)), but a destination persistent store containing the entity type could not be found.") + fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)), but a destination persistent store containing the entity type could not be found.") } } else { @@ -90,11 +90,11 @@ public /*abstract*/ class BaseDataTransaction { default: if let configuration = into.configuration { - fatalError("Attempted to create an entity of type \(typeName(entityClass)) into the configuration \"\(configuration)\", which it doesn't belong to.") + fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) into the configuration \"\(configuration)\", which it doesn't belong to.") } else { - fatalError("Attempted to create an entity of type \(typeName(entityClass)) into the default configuration, which it doesn't belong to.") + fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) into the default configuration, which it doesn't belong to.") } } } @@ -111,7 +111,7 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to update an entity of type \(typeName(object)) outside its designated queue." + "Attempted to update an entity of type \(cs_typeName(object)) outside its designated queue." ) guard let object = object else { @@ -132,12 +132,12 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.isRunningInAllowedQueue(), - "Attempted to update an entity of type \(typeName(T)) outside its designated queue." + "Attempted to update an entity of type \(cs_typeName(T)) outside its designated queue." ) CoreStore.assert( into.inferStoreIfPossible || (into.configuration ?? Into.defaultConfigurationName) == objectID.persistentStore?.configurationName, - "Attempted to update an entity of type \(typeName(T)) but the specified persistent store do not match the `NSManagedObjectID`." + "Attempted to update an entity of type \(cs_typeName(T)) but the specified persistent store do not match the `NSManagedObjectID`." ) return self.fetchExisting(objectID) as? T } @@ -214,11 +214,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access inserted objects from a \(typeName(self)) outside its designated queue." + "Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access inserted objects from an already committed \(typeName(self))." + "Attempted to access inserted objects from an already committed \(cs_typeName(self))." ) return self.context.insertedObjects @@ -235,11 +235,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access inserted objects from a \(typeName(self)) outside its designated queue." + "Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access inserted objects from an already committed \(typeName(self))." + "Attempted to access inserted objects from an already committed \(cs_typeName(self))." ) return Set(self.context.insertedObjects.flatMap { $0 as? T }) @@ -255,11 +255,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access inserted object IDs from a \(typeName(self)) outside its designated queue." + "Attempted to access inserted object IDs from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access inserted objects IDs from an already committed \(typeName(self))." + "Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))." ) return Set(self.context.insertedObjects.map { $0.objectID }) @@ -276,11 +276,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access inserted object IDs from a \(typeName(self)) outside its designated queue." + "Attempted to access inserted object IDs from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access inserted objects IDs from an already committed \(typeName(self))." + "Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))." ) return Set(self.context.insertedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID }) @@ -296,11 +296,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access updated objects from a \(typeName(self)) outside its designated queue." + "Attempted to access updated objects from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access updated objects from an already committed \(typeName(self))." + "Attempted to access updated objects from an already committed \(cs_typeName(self))." ) return self.context.updatedObjects @@ -317,11 +317,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access updated objects from a \(typeName(self)) outside its designated queue." + "Attempted to access updated objects from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access updated objects from an already committed \(typeName(self))." + "Attempted to access updated objects from an already committed \(cs_typeName(self))." ) return Set(self.context.updatedObjects.filter { $0.isKindOfClass(entity) }.map { $0 as! T }) @@ -337,11 +337,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access updated object IDs from a \(typeName(self)) outside its designated queue." + "Attempted to access updated object IDs from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access updated object IDs from an already committed \(typeName(self))." + "Attempted to access updated object IDs from an already committed \(cs_typeName(self))." ) return Set(self.context.updatedObjects.map { $0.objectID }) @@ -358,11 +358,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access updated object IDs from a \(typeName(self)) outside its designated queue." + "Attempted to access updated object IDs from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access updated object IDs from an already committed \(typeName(self))." + "Attempted to access updated object IDs from an already committed \(cs_typeName(self))." ) return Set(self.context.updatedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID }) @@ -378,11 +378,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access deleted objects from a \(typeName(self)) outside its designated queue." + "Attempted to access deleted objects from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access deleted objects from an already committed \(typeName(self))." + "Attempted to access deleted objects from an already committed \(cs_typeName(self))." ) return self.context.deletedObjects @@ -399,11 +399,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access deleted objects from a \(typeName(self)) outside its designated queue." + "Attempted to access deleted objects from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access deleted objects from an already committed \(typeName(self))." + "Attempted to access deleted objects from an already committed \(cs_typeName(self))." ) return Set(self.context.deletedObjects.filter { $0.isKindOfClass(entity) }.map { $0 as! T }) @@ -420,11 +420,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access deleted object IDs from a \(typeName(self)) outside its designated queue." + "Attempted to access deleted object IDs from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access deleted object IDs from an already committed \(typeName(self))." + "Attempted to access deleted object IDs from an already committed \(cs_typeName(self))." ) return Set(self.context.deletedObjects.map { $0.objectID }) @@ -441,11 +441,11 @@ public /*abstract*/ class BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to access deleted object IDs from a \(typeName(self)) outside its designated queue." + "Attempted to access deleted object IDs from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to access deleted object IDs from an already committed \(typeName(self))." + "Attempted to access deleted object IDs from an already committed \(cs_typeName(self))." ) return Set(self.context.deletedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID }) diff --git a/Sources/Transactions/SynchronousDataTransaction.swift b/Sources/Transactions/SynchronousDataTransaction.swift index 56b10db..2725f91 100644 --- a/Sources/Transactions/SynchronousDataTransaction.swift +++ b/Sources/Transactions/SynchronousDataTransaction.swift @@ -46,11 +46,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to commit a \(typeName(self)) outside its designated queue." + "Attempted to commit a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to commit a \(typeName(self)) more than once." + "Attempted to commit a \(cs_typeName(self)) more than once." ) self.isCommitted = true @@ -70,11 +70,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to begin a child transaction from a \(typeName(self)) outside its designated queue." + "Attempted to begin a child transaction from a \(cs_typeName(self)) outside its designated queue." ) CoreStore.assert( !self.isCommitted, - "Attempted to begin a child transaction from an already committed \(typeName(self))." + "Attempted to begin a child transaction from an already committed \(cs_typeName(self))." ) return SynchronousDataTransaction( @@ -96,7 +96,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to create an entity of type \(typeName(T)) from an already committed \(typeName(self))." + "Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))." ) return super.create(into) @@ -113,7 +113,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to update an entity of type \(typeName(object)) from an already committed \(typeName(self))." + "Attempted to update an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))." ) return super.edit(object) @@ -131,7 +131,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to update an entity of type \(typeName(T)) from an already committed \(typeName(self))." + "Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))." ) return super.edit(into, objectID) @@ -146,7 +146,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to delete an entity of type \(typeName(object)) from an already committed \(typeName(self))." + "Attempted to delete an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))." ) super.delete(object) @@ -163,7 +163,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to delete an entities from an already committed \(typeName(self))." + "Attempted to delete an entities from an already committed \(cs_typeName(self))." ) super.delete(([object1, object2] + objects).flatMap { $0 }) @@ -178,7 +178,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to delete an entities from an already committed \(typeName(self))." + "Attempted to delete an entities from an already committed \(cs_typeName(self))." ) super.delete(objects) @@ -204,7 +204,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.log( .Warning, - message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded." + message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded." ) } } @@ -224,11 +224,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction { CoreStore.assert( !self.isCommitted, - "Attempted to rollback an already committed \(typeName(self))." + "Attempted to rollback an already committed \(cs_typeName(self))." ) CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), - "Attempted to rollback a \(typeName(self)) outside its designated queue." + "Attempted to rollback a \(cs_typeName(self)) outside its designated queue." ) self.context.reset() diff --git a/Sources/Transactions/UnsafeDataTransaction.swift b/Sources/Transactions/UnsafeDataTransaction.swift index 6dbb171..54bae12 100644 --- a/Sources/Transactions/UnsafeDataTransaction.swift +++ b/Sources/Transactions/UnsafeDataTransaction.swift @@ -70,7 +70,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction { CoreStore.assert( self.supportsUndo, - "Attempted to rollback a \(typeName(self)) with Undo support disabled." + "Attempted to rollback a \(cs_typeName(self)) with Undo support disabled." ) self.context.rollback() } @@ -82,7 +82,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction { CoreStore.assert( self.supportsUndo, - "Attempted to undo a \(typeName(self)) with Undo support disabled." + "Attempted to undo a \(cs_typeName(self)) with Undo support disabled." ) self.context.undo() } @@ -94,7 +94,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction { CoreStore.assert( self.supportsUndo, - "Attempted to redo a \(typeName(self)) with Undo support disabled." + "Attempted to redo a \(cs_typeName(self)) with Undo support disabled." ) self.context.redo() }