diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index 7442f9a..b4dc129 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -166,10 +166,6 @@ B546F96A1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */; }; B546F96B1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */; }; B546F96C1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */; }; - B546F96E1C9B14AC00D5AC55 /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */; }; - B546F96F1C9B14AC00D5AC55 /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */; }; - B546F9701C9B14AC00D5AC55 /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */; }; - B546F9711C9B14AC00D5AC55 /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */; }; B546F9731C9C553300D5AC55 /* SetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9721C9C553300D5AC55 /* SetupResult.swift */; }; B546F9741C9C553300D5AC55 /* SetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9721C9C553300D5AC55 /* SetupResult.swift */; }; B546F9751C9C553300D5AC55 /* SetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9721C9C553300D5AC55 /* SetupResult.swift */; }; @@ -191,6 +187,16 @@ B5519A611CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; }; B5519A621CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; }; B5598BCC1BE2093D0092EFCE /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = B5D372821A39CD6900F583D9 /* Model.xcdatamodeld */; }; + B559CD431CAA8B6300E4D58B /* CSSetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */; }; + B559CD441CAA8B6300E4D58B /* CSSetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */; }; + B559CD451CAA8B6300E4D58B /* CSSetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */; }; + B559CD461CAA8B6300E4D58B /* CSSetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */; }; + B559CD471CAA8B6300E4D58B /* CSSetupResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */; }; + B559CD491CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */; }; + B559CD4A1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */; }; + B559CD4B1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */; }; + B559CD4C1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */; }; + B559CD4D1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */; }; B56007111B3F6BD500A9A8F9 /* Into.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56007101B3F6BD500A9A8F9 /* Into.swift */; }; B56007141B3F6C2800A9A8F9 /* SectionBy.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56007131B3F6C2800A9A8F9 /* SectionBy.swift */; }; B56007161B4018AB00A9A8F9 /* MigrationChain.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56007151B4018AB00A9A8F9 /* MigrationChain.swift */; }; @@ -507,7 +513,6 @@ B5ECDC3C1CA836B600C7F112 /* CSCoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5DBE2CC1C9914A900B5CEFA /* CSCoreStore.swift */; }; B5ECDC3D1CA836BA00C7F112 /* CSError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A491CA1F4FB002BEF78 /* CSError.swift */; }; B5ECDC3E1CA836BE00C7F112 /* CSCoreStore+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9571C99B17400D5AC55 /* CSCoreStore+Setup.swift */; }; - B5ECDC3F1CA836C400C7F112 /* CSStorageInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */; }; B5ECDC401CA836C800C7F112 /* CSInMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */; }; B5ECDC411CA836C800C7F112 /* CSSQliteStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */; }; B5ECDC421CA836CF00C7F112 /* CSAsynchronousDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */; }; @@ -586,7 +591,6 @@ B546F9571C99B17400D5AC55 /* CSCoreStore+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSCoreStore+Setup.swift"; sourceTree = ""; }; B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSQliteStore.swift; sourceTree = ""; }; B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSInMemoryStore.swift; sourceTree = ""; }; - B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSStorageInterface.swift; sourceTree = ""; }; B546F9721C9C553300D5AC55 /* SetupResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupResult.swift; sourceTree = ""; }; B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedResultsControllerDelegate.swift; sourceTree = ""; }; B5519A3F1CA1B17B002BEF78 /* ErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTests.swift; sourceTree = ""; }; @@ -595,6 +599,8 @@ B5519A5E1CA21954002BEF78 /* CSAsynchronousDataTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSAsynchronousDataTransaction.swift; sourceTree = ""; }; B5548CD51BD65AE00077652A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; B5548CD71BD65AE50077652A /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; }; + B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSetupResult.swift; sourceTree = ""; }; + B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSStorageInterface.swift; sourceTree = ""; }; B56007101B3F6BD500A9A8F9 /* Into.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Into.swift; sourceTree = ""; }; B56007131B3F6C2800A9A8F9 /* SectionBy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionBy.swift; sourceTree = ""; }; B56007151B4018AB00A9A8F9 /* MigrationChain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationChain.swift; sourceTree = ""; }; @@ -909,7 +915,7 @@ B546F9621C9A140E00D5AC55 /* StorageInterfaces */ = { isa = PBXGroup; children = ( - B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */, + B559CD481CAA8C6D00E4D58B /* CSStorageInterface.swift */, B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */, B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */, ); @@ -977,6 +983,7 @@ isa = PBXGroup; children = ( B5E1B5A71CAA49E2007FD580 /* CSDataStack+Migrating.swift */, + B559CD421CAA8B6300E4D58B /* CSSetupResult.swift */, ); name = Migrating; sourceTree = ""; @@ -1512,7 +1519,6 @@ B5202CFA1C04688100DED140 /* NSFetchedResultsController+Convenience.swift in Sources */, B5519A591CA2008C002BEF78 /* CSBaseDataTransaction.swift in Sources */, B5ECDBDF1CA6BB2B00C7F112 /* CSBaseDataTransaction+Querying.swift in Sources */, - B546F96E1C9B14AC00D5AC55 /* CSStorageInterface.swift in Sources */, B5E84F251AFF84860064E85B /* ObjectObserver.swift in Sources */, B5E84F2F1AFF849C0064E85B /* NotificationObserver.swift in Sources */, B5F1DA8D1B9AA97D007C5CBB /* ImportableObject.swift in Sources */, @@ -1548,6 +1554,7 @@ B5E2222A1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, B5E84F391AFF85470064E85B /* NSManagedObjectContext+Querying.swift in Sources */, B5E84EE81AFF84610064E85B /* CoreStoreLogger.swift in Sources */, + B559CD491CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B5ECDC2F1CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, B5E84F311AFF849C0064E85B /* WeakObject.swift in Sources */, B5E84F101AFF847B0064E85B /* GroupBy.swift in Sources */, @@ -1557,6 +1564,7 @@ B5E84F301AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift in Sources */, B546F9691C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */, B5E84F211AFF84860064E85B /* CoreStore+Observing.swift in Sources */, + B559CD431CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, B5FE4DA71C84FB4400FA6A91 /* InMemoryStore.swift in Sources */, B5ECDBEC1CA6BF2000C7F112 /* CSFrom.swift in Sources */, B5E834B91B76311F001D3D50 /* BaseDataTransaction+Importing.swift in Sources */, @@ -1632,7 +1640,6 @@ 82BA18CA1C4BBD5900A0916E /* MigrationResult.swift in Sources */, B5519A5A1CA2008C002BEF78 /* CSBaseDataTransaction.swift in Sources */, B5ECDBE11CA6BB2B00C7F112 /* CSBaseDataTransaction+Querying.swift in Sources */, - B546F96F1C9B14AC00D5AC55 /* CSStorageInterface.swift in Sources */, 82BA18C11C4BBD5300A0916E /* CoreStore+Observing.swift in Sources */, 82BA18BC1C4BBD4A00A0916E /* OrderBy.swift in Sources */, 82BA18B01C4BBD3100A0916E /* NSManagedObject+Transaction.swift in Sources */, @@ -1668,6 +1675,7 @@ B5E2222C1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, 82BA18A71C4BBD2900A0916E /* CoreStore+Logging.swift in Sources */, 82BA18D81C4BBD7100A0916E /* WeakObject.swift in Sources */, + B559CD4B1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B5ECDC311CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, 82BA18AF1C4BBD3100A0916E /* CoreStore+Transaction.swift in Sources */, 82BA18CB1C4BBD6400A0916E /* NSManagedObject+Convenience.swift in Sources */, @@ -1677,6 +1685,7 @@ 82BA18AD1C4BBD3100A0916E /* UnsafeDataTransaction.swift in Sources */, B546F96A1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */, 82BA18A81C4BBD2900A0916E /* CoreStoreLogger.swift in Sources */, + B559CD451CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, 82BA18B81C4BBD4200A0916E /* ClauseTypes.swift in Sources */, B5ECDBEE1CA6BF2000C7F112 /* CSFrom.swift in Sources */, 82BA18D61C4BBD7100A0916E /* NSManagedObjectContext+Transaction.swift in Sources */, @@ -1730,6 +1739,7 @@ B5D3F6481C887C0A00C7492A /* LegacySQLiteStore.swift in Sources */, B52DD19E1BE1F92C00949AFE /* AsynchronousDataTransaction.swift in Sources */, B52DD1981BE1F92500949AFE /* CoreStore+Setup.swift in Sources */, + B559CD471CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, B5ECDBF01CA6BF2000C7F112 /* CSFrom.swift in Sources */, B52DD1941BE1F92500949AFE /* CoreStore.swift in Sources */, B52DD1A61BE1F92F00949AFE /* BaseDataTransaction+Importing.swift in Sources */, @@ -1750,6 +1760,7 @@ B52DD1A81BE1F93200949AFE /* DataStack+Querying.swift in Sources */, B52DD1BC1BE1F94000949AFE /* MigrationResult.swift in Sources */, B52DD19D1BE1F92C00949AFE /* BaseDataTransaction.swift in Sources */, + B559CD4D1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B5ECDBE91CA6BEA300C7F112 /* CSClauseTypes.swift in Sources */, B52DD1B81BE1F94000949AFE /* DataStack+Migration.swift in Sources */, B5ECDC091CA8138100C7F112 /* CSOrderBy.swift in Sources */, @@ -1758,7 +1769,6 @@ B5519A621CA21954002BEF78 /* CSAsynchronousDataTransaction.swift in Sources */, B52DD19C1BE1F92C00949AFE /* Into.swift in Sources */, B5FE4DA51C8481E100FA6A91 /* StorageInterface.swift in Sources */, - B546F9711C9B14AC00D5AC55 /* CSStorageInterface.swift in Sources */, B529C2081CA4A2DC007E7EBD /* CSSaveResult.swift in Sources */, B5FE4DAA1C84FB4400FA6A91 /* InMemoryStore.swift in Sources */, B52DD1AF1BE1F93900949AFE /* GroupBy.swift in Sources */, @@ -1853,7 +1863,6 @@ B50392FA1C47963F009900CA /* NSManagedObject+Transaction.swift in Sources */, B5519A5B1CA2008C002BEF78 /* CSBaseDataTransaction.swift in Sources */, B5ECDBE21CA6BB2B00C7F112 /* CSBaseDataTransaction+Querying.swift in Sources */, - B546F9701C9B14AC00D5AC55 /* CSStorageInterface.swift in Sources */, B56321971BD65216006C9394 /* Select.swift in Sources */, B56321AB1BD6521C006C9394 /* FetchedResultsControllerDelegate.swift in Sources */, B563219C1BD65216006C9394 /* SectionBy.swift in Sources */, @@ -1890,6 +1899,7 @@ B5E2222D1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, B563219F1BD65216006C9394 /* ObjectMonitor.swift in Sources */, B56321B61BD6521C006C9394 /* WeakObject.swift in Sources */, + B559CD4C1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B5ECDC321CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, B56321AC1BD6521C006C9394 /* Functions.swift in Sources */, B56321851BD65216006C9394 /* CoreStore+Logging.swift in Sources */, @@ -1899,6 +1909,7 @@ B563218D1BD65216006C9394 /* CoreStore+Transaction.swift in Sources */, B546F96B1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */, B563218B1BD65216006C9394 /* UnsafeDataTransaction.swift in Sources */, + B559CD461CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, B56321A61BD65216006C9394 /* MigrationType.swift in Sources */, B5ECDBEF1CA6BF2000C7F112 /* CSFrom.swift in Sources */, B56321B41BD6521C006C9394 /* NSManagedObjectContext+Transaction.swift in Sources */, @@ -1919,7 +1930,6 @@ files = ( B5ECDC0C1CA8161B00C7F112 /* CSGroupBy.swift in Sources */, B5EA11DD1CA3AFD9002282F8 /* NSPersistentStoreCoordinator+Setup.swift in Sources */, - B5ECDC3F1CA836C400C7F112 /* CSStorageInterface.swift in Sources */, B5ECDC3A1CA8369400C7F112 /* CSDataStack.swift in Sources */, B5D9E2EF1CA2C317007A9D52 /* ObjectMonitor.swift in Sources */, B5ECDC3B1CA836AD00C7F112 /* CoreStoreBridge.swift in Sources */, @@ -1983,6 +1993,7 @@ B5ECDBE01CA6BB2B00C7F112 /* CSBaseDataTransaction+Querying.swift in Sources */, B5D9E3131CA2C317007A9D52 /* DataStack+Migration.swift in Sources */, B5D9E3141CA2C317007A9D52 /* BaseDataTransaction.swift in Sources */, + B559CD441CAA8B6300E4D58B /* CSSetupResult.swift in Sources */, B5E1B59E1CAA2568007FD580 /* CSDataStack+Observing.swift in Sources */, B5ECDC241CA81A3900C7F112 /* CSCoreStore+Querying.swift in Sources */, B5D9E3151CA2C317007A9D52 /* SaveResult.swift in Sources */, @@ -1994,6 +2005,7 @@ B5D9E3181CA2C317007A9D52 /* NSProgress+Convenience.swift in Sources */, B5D9E3191CA2C317007A9D52 /* SynchronousDataTransaction.swift in Sources */, B5ECDBE61CA6BEA300C7F112 /* CSClauseTypes.swift in Sources */, + B559CD4A1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B5D9E31A1CA2C317007A9D52 /* NSManagedObject+Convenience.swift in Sources */, B5D9E31B1CA2C317007A9D52 /* NSManagedObjectModel+Setup.swift in Sources */, B5D7A5B01CA3B738005C752B /* StorageInterface.swift in Sources */, diff --git a/CoreStoreTests/BridgingTests.m b/CoreStoreTests/BridgingTests.m index c2900f5..792037d 100644 --- a/CoreStoreTests/BridgingTests.m +++ b/CoreStoreTests/BridgingTests.m @@ -33,10 +33,10 @@ - (void)testFlags { - XCTAssertEqual([CSLocalStorageOptions none], 0); - XCTAssertEqual([CSLocalStorageOptions recreateStoreOnModelMismatch], 1); - XCTAssertEqual([CSLocalStorageOptions preventProgressiveMigration], 2); - XCTAssertEqual([CSLocalStorageOptions allowSynchronousLightweightMigration], 4); + XCTAssertEqual(CSLocalStorageOptionsNone, 0); + XCTAssertEqual(CSLocalStorageOptionsRecreateStoreOnModelMismatch, 1); + XCTAssertEqual(CSLocalStorageOptionsPreventProgressiveMigration, 2); + XCTAssertEqual(CSLocalStorageOptionsAllowSynchronousLightweightMigration, 4); } - (void)testDataStack { diff --git a/Sources/Migrating/SetupResult.swift b/Sources/Migrating/SetupResult.swift index 112d3c7..c2d7575 100644 --- a/Sources/Migrating/SetupResult.swift +++ b/Sources/Migrating/SetupResult.swift @@ -60,7 +60,7 @@ import CoreData ) ``` */ -public enum SetupResult: BooleanType { +public enum SetupResult: BooleanType, Hashable { /** `SetupResult.Success` indicates that the storage setup succeeded. The associated object for this `enum` value is the related `StorageInterface` instance. @@ -85,6 +85,21 @@ public enum SetupResult: BooleanType { } + // MARK: Hashable + + public var hashValue: Int { + + switch self { + + case .Success(let storage): + return self.boolValue.hashValue ^ ObjectIdentifier(storage).hashValue + + case .Failure(let error): + return self.boolValue.hashValue ^ error.hashValue + } + } + + // MARK: Internal internal init(_ storage: T) { @@ -104,8 +119,26 @@ public enum SetupResult: BooleanType { } -// MARK: - Deprecated +// MARK: - SetupResult: Equatable +@warn_unused_result +public func == (lhs: SetupResult, rhs: SetupResult) -> Bool { + + switch (lhs, rhs) { + + case (.Success(let storage1), .Success(let storage2)): + return storage1 === storage2 + + case (.Failure(let error1), .Failure(let error2)): + return error1 == error2 + + default: + return false + } +} + + +// MARK: - Deprecated /** Deprecated. Replaced by `SetupResult` when using the new `addStorage(_:completion:)` method variants. diff --git a/Sources/ObjectiveC/CSDataStack+Migrating.swift b/Sources/ObjectiveC/CSDataStack+Migrating.swift index 74072a8..74ae3d9 100644 --- a/Sources/ObjectiveC/CSDataStack+Migrating.swift +++ b/Sources/ObjectiveC/CSDataStack+Migrating.swift @@ -48,7 +48,7 @@ public extension CSDataStack { // - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a `.Failure` result if an error occurs asynchronously. // - returns: an `NSProgress` instance if a migration has started, or `nil` is no migrations are required // */ -// public func addStorage(storage: StorageInterface, completion: (SetupResult) -> Void) throws -> NSProgress? { +// public func addInMemoryStorage(storage: CSInMemoryStore, completion: (CSSetupResult) -> Void, error: NSErrorPointer) -> NSProgress? { // // self.coordinator.performAsynchronously { // @@ -91,7 +91,7 @@ public extension CSDataStack { // // return nil // } -// +// // /** // Asynchronously adds a `LocalStorage` with default settings to the stack. Migrations are also initiated by default. // ``` diff --git a/Sources/ObjectiveC/CSDataStack.swift b/Sources/ObjectiveC/CSDataStack.swift index d1a6a40..1a36694 100644 --- a/Sources/ObjectiveC/CSDataStack.swift +++ b/Sources/ObjectiveC/CSDataStack.swift @@ -229,7 +229,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType { try self.bridgeToSwift.addStorageAndWait(storage.bridgeToSwift) } } - + // MARK: NSObject diff --git a/Sources/ObjectiveC/CSObjectObserver.swift b/Sources/ObjectiveC/CSObjectObserver.swift index 3a298a0..2b6e079 100644 --- a/Sources/ObjectiveC/CSObjectObserver.swift +++ b/Sources/ObjectiveC/CSObjectObserver.swift @@ -57,7 +57,7 @@ public protocol CSObjectObserver: class, AnyObject { - parameter changedPersistentKeys: an `NSSet` of key paths for the attributes that were changed. Note that `changedPersistentKeys` only contains keys for attributes/relationships present in the persistent store, thus transient properties will not be reported. */ @objc - optional func objectMonitor(monitor: CSObjectMonitor, didUpdateObject object: NSManagedObject, changedPersistentKeys: Set) + optional func objectMonitor(monitor: CSObjectMonitor, didUpdateObject object: NSManagedObject, changedPersistentKeys: Set) /** Handles processing right after `object` is deleted diff --git a/Sources/ObjectiveC/CSSQliteStore.swift b/Sources/ObjectiveC/CSSQliteStore.swift index 934ca01..e0d2ce8 100644 --- a/Sources/ObjectiveC/CSSQliteStore.swift +++ b/Sources/ObjectiveC/CSSQliteStore.swift @@ -41,7 +41,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT - parameter fileURL: the local file URL for the target SQLite persistent store. Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them. - parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration. Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them. - parameter mappingModelBundles: a list of `NSBundle`s from which to search mapping models for migration. - - parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `[CSLocalStorageOptions none]`. + - parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `CSLocalStorageOptionsNone`. */ @objc public convenience init(fileURL: NSURL, configuration: String?, mappingModelBundles: [NSBundle]?, localStorageOptions: Int) { diff --git a/Sources/ObjectiveC/CSSetupResult.swift b/Sources/ObjectiveC/CSSetupResult.swift new file mode 100644 index 0000000..ec6de8e --- /dev/null +++ b/Sources/ObjectiveC/CSSetupResult.swift @@ -0,0 +1,190 @@ +// +// CSSetupResult.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 +import CoreData + + +// MARK: - CSSetupResult + +/** + The `CSSetupResult` serves as the Objective-C bridging type for `SetupResult`. + */ +@objc +public final class CSSetupResult: NSObject { + + /** + `YES` if the `commit` operation for the transaction succeeded, either because the save succeeded or because there were no changes to save. Returns `NO` to indicate failure. + */ + @objc + public var isSuccess: Bool { + + return self.bridgeToSwift.boolValue + } + + /** + `YES` if the `commit` operation for the transaction failed, or `NO` otherwise. When `YES`, the `error` property returns the actual `NSError` for the failure. + */ + @objc + public var isFailure: Bool { + + return !self.bridgeToSwift.boolValue + } + + /** + A `CSStorageInterface` instance if the `commit` operation for the transaction succeeded. Returns `NO` otherwise. + */ + @objc + public var storage: CSStorageInterface? { + + guard case .Success(let storage as CoreStoreSwiftType) = self.bridgeToSwift else { + + return nil + } + return storage.bridgeToObjectiveC + } + + /** + The `NSError` for a failed `commit` operation, or `nil` if the `commit` succeeded + */ + @objc + public var error: NSError? { + + guard case .Failure(let error) = self.bridgeToSwift else { + + return nil + } + return error.bridgeToObjectiveC + } + + /** + If the result was a success, the `success` block is executed with a `BOOL` argument that indicates if there were any changes made. If the result was a failure, the `failure` block is executed with an `NSError` argument pertaining to the actual error. + + The blocks are executed immediately as `@noescape` and will not be retained. + + - parameter success: the block to execute on success. The block passes a `BOOL` argument that indicates if there were any changes made. + - parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actuall error. + */ + @objc + public func handleSuccess(@noescape success: (storage: CSStorageInterface) -> Void, @noescape failure: (error: NSError) -> Void) { + + switch self.bridgeToSwift { + + case .Success(let storage): + success(storage: storage.bridgeToObjectiveC) + + case .Failure(let error): + failure(error: error.bridgeToObjectiveC) + } + } + + /** + If the result was a success, the `success` block is executed with a `BOOL` argument that indicates if there were any changes made. If the result was a failure, this method does nothing. + + The block is executed immediately as `@noescape` and will not be retained. + + - parameter success: the block to execute on success. The block passes a `BOOL` argument that indicates if there were any changes made. + */ + @objc + public func handleSuccess(@noescape success: (storage: CSStorageInterface) -> Void) { + + guard let storageInterface = self.storageInterface else { + + return + } + success(storage: storage) + } + + /** + If the result was a failure, the `failure` block is executed with an `NSError` argument pertaining to the actual error. If the result was a success, this method does nothing. + + The block is executed immediately as `@noescape` and will not be retained. + + - parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actuall error. + */ + @objc + public func handleFailure(@noescape failure: (error: NSError) -> Void) { + + guard let coreStoreError = self.coreStoreError else { + + return + } + failure(error: coreStoreError.bridgeToObjectiveC) + } + + + // MARK: NSObject + + public override var hash: Int { + + if let storageInterface = self.storageInterface { + + return self.isSuccess.hashValue ^ ObjectIdentifier(storageInterface).hashValue + } + return self.isSuccess.hashValue ^ self.coreStoreError!.hashValue + } + + public override func isEqual(object: AnyObject?) -> Bool { + + guard let object = object as? CSSetupResult else { + + return false + } + return self.storageInterface === object.storageInterface + && self.coreStoreError == object.coreStoreError + } + + + // MARK: CoreStoreObjectiveCType + + public required init(_ swiftValue: SetupResult) { + + switch swiftValue { + + case .Success(let storage): + self.storageInterface = storage + + case .Failure(let error): + self.coreStoreError = error + } + super.init() + } + + private var storageInterface: StorageInterface? + private var coreStoreError: CoreStoreError? +} + + +// MARK: - SetupResult + +extension SetupResult { + + // MARK: CoreStoreSwiftType + + public var bridgeToObjectiveC: CSSetupResult { + + return CSSetupResult(self) + } +} diff --git a/Sources/ObjectiveC/CSStorageInterface.swift b/Sources/ObjectiveC/CSStorageInterface.swift index e0df8ac..0a15e49 100644 --- a/Sources/ObjectiveC/CSStorageInterface.swift +++ b/Sources/ObjectiveC/CSStorageInterface.swift @@ -2,11 +2,32 @@ // CSStorageInterface.swift // CoreStore // -// Created by John Rommel Estropia on 2016/03/18. -// Copyright © 2016 John Rommel Estropia. All rights reserved. +// 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 UIKit +import Foundation +import CoreData + + +// MARK: - CSStorageInterface /** The `CSStorageInterface` serves as the Objective-C bridging type for `StorageInterface`. @@ -40,39 +61,27 @@ public protocol CSStorageInterface { The `CSLocalStorageOptions` provides settings that tells the `CSDataStack` how to setup the persistent store for `CSLocalStorage` implementers. */ @objc -public final class CSLocalStorageOptions: NSObject { +public enum CSLocalStorageOptions: Int { /** Tells the `DataStack` that the store should not be migrated or recreated, and should simply fail on model mismatch */ - @objc - public static let none = 0 + case None = 0 /** Tells the `DataStack` to delete and recreate the store on model mismatch, otherwise exceptions will be thrown on failure instead */ - @objc - public static let recreateStoreOnModelMismatch = 1 + case RecreateStoreOnModelMismatch = 1 /** Tells the `DataStack` to prevent progressive migrations for the store */ - @objc - public static let preventProgressiveMigration = 2 + case PreventProgressiveMigration = 2 /** Tells the `DataStack` to allow lightweight migration for the store when added synchronously */ - @objc - public static let allowSynchronousLightweightMigration = 4 - - - // MARK: Private - - private override init() { - - fatalError() - } + case AllowSynchronousLightweightMigration = 4 }