From 789028bc58e63c455c12dceb4d42d8be75a66183 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 25 Mar 2016 19:59:31 +0900 Subject: [PATCH] WIP: CSImportableUniqueObject --- CoreStore.xcodeproj/project.pbxproj | 4 +++- .../FetchingAndQueryingDemoViewController.swift | 2 +- .../ListObserverDemoViewController.swift | 2 +- .../CustomLoggerViewController.swift | 2 +- .../StackSetupDemoViewController.swift | 8 ++++---- .../TransactionsDemoViewController.swift | 2 +- Sources/ObjectiveC/CSImportableObject.swift | 16 ++++++++++++---- Sources/ObjectiveC/CSSaveResult.swift | 6 +++--- Sources/ObjectiveC/CSUnsafeDataTransaction.swift | 4 ++-- 9 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index 0a1b27c..cc1020d 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -247,6 +247,7 @@ B59851491C90289D00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; }; B598514A1C90289E00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; }; B598514B1C90289F00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; }; + B59983491CA54BC100E1A417 /* CSBaseDataTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5519A581CA2008C002BEF78 /* CSBaseDataTransaction.swift */; }; B59AFF411C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; }; B59D5C221B5BA34B00453479 /* NSFileManager+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59D5C211B5BA34B00453479 /* NSFileManager+Setup.swift */; }; B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A261201B64BFDB006EB6D3 /* MigrationType.swift */; }; @@ -844,9 +845,9 @@ children = ( B5DBE2CC1C9914A900B5CEFA /* CSCoreStore.swift */, B5519A491CA1F4FB002BEF78 /* CSError.swift */, - B5E2222F1CA5339200BA2E95 /* Importing Data */, B546F9611C9A13F400D5AC55 /* Setup */, B5519A5D1CA20093002BEF78 /* Saving and Processing */, + B5E2222F1CA5339200BA2E95 /* Importing Data */, B5E222211CA4DE5700BA2E95 /* Internal */, ); path = ObjectiveC; @@ -1702,6 +1703,7 @@ files = ( B5EA11DD1CA3AFD9002282F8 /* NSPersistentStoreCoordinator+Setup.swift in Sources */, B5D9E2EF1CA2C317007A9D52 /* ObjectMonitor.swift in Sources */, + B59983491CA54BC100E1A417 /* CSBaseDataTransaction.swift in Sources */, B5E2222B1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, B5D9E2F01CA2C317007A9D52 /* CoreStoreFetchedResultsController.swift in Sources */, B5D9E3461CA2C6C4007A9D52 /* GCDQueue.swift in Sources */, diff --git a/CoreStoreDemo/CoreStoreDemo/Fetching and Querying Demo/FetchingAndQueryingDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/Fetching and Querying Demo/FetchingAndQueryingDemoViewController.swift index b9d2a8a..dbb113b 100644 --- a/CoreStoreDemo/CoreStoreDemo/Fetching and Querying Demo/FetchingAndQueryingDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Fetching and Querying Demo/FetchingAndQueryingDemoViewController.swift @@ -19,7 +19,7 @@ private struct Static { SQLiteStore( fileName: "TimeZoneDemo.sqlite", configuration: "FetchingAndQueryingDemo", - resetStoreOnModelMismatch: true + localStorageOptions: .RecreateStoreOnModelMismatch ) ) diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift index 1df7145..1a5121d 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift @@ -53,7 +53,7 @@ private struct Static { SQLiteStore( fileName: "ColorsDemo.sqlite", configuration: "ObservingDemo", - resetStoreOnModelMismatch: true + localStorageOptions: .RecreateStoreOnModelMismatch ) ) diff --git a/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift b/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift index bd29847..81fcf29 100644 --- a/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift @@ -66,7 +66,7 @@ class CustomLoggerViewController: UIViewController, CoreStoreLogger { } } - func handleError(error error: NSError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { + func log(error error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { GCDQueue.Main.async { [weak self] in diff --git a/CoreStoreDemo/CoreStoreDemo/Stack Setup Demo/StackSetupDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/Stack Setup Demo/StackSetupDemoViewController.swift index ab8d9be..e6bdbbf 100644 --- a/CoreStoreDemo/CoreStoreDemo/Stack Setup Demo/StackSetupDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Stack Setup Demo/StackSetupDemoViewController.swift @@ -22,14 +22,14 @@ private struct Static { SQLiteStore( fileName: "AccountsDemo_FB_Male.sqlite", configuration: maleConfiguration, - resetStoreOnModelMismatch: true + localStorageOptions: .RecreateStoreOnModelMismatch ) ) try! dataStack.addStorageAndWait( SQLiteStore( fileName: "AccountsDemo_FB_Female.sqlite", configuration: femaleConfiguration, - resetStoreOnModelMismatch: true + localStorageOptions: .RecreateStoreOnModelMismatch ) ) @@ -60,14 +60,14 @@ private struct Static { SQLiteStore( fileName: "AccountsDemo_TW_Male.sqlite", configuration: maleConfiguration, - resetStoreOnModelMismatch: true + localStorageOptions: .RecreateStoreOnModelMismatch ) ) try! dataStack.addStorageAndWait( SQLiteStore( fileName: "AccountsDemo_TW_Female.sqlite", configuration: femaleConfiguration, - resetStoreOnModelMismatch: true + localStorageOptions: .RecreateStoreOnModelMismatch ) ) diff --git a/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift index e86a88b..03d1ba3 100644 --- a/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift @@ -22,7 +22,7 @@ private struct Static { SQLiteStore( fileName: "PlaceDemo.sqlite", configuration: "TransactionsDemo", - resetStoreOnModelMismatch: true + localStorageOptions: .RecreateStoreOnModelMismatch ) ) diff --git a/Sources/ObjectiveC/CSImportableObject.swift b/Sources/ObjectiveC/CSImportableObject.swift index bb2d406..3080d18 100644 --- a/Sources/ObjectiveC/CSImportableObject.swift +++ b/Sources/ObjectiveC/CSImportableObject.swift @@ -33,17 +33,25 @@ import CoreData public protocol CSImportableObject: class, AnyObject { /** - Return `true` if an object should be created from `source`. Return `false` to ignore and skip `source`. The default implementation returns `true`. + Return the expected class of the import source. If not implemented, transactions will not validate the import source's type. + + - returns: the expected class of the import source + */ + @objc + optional static func classForImportSource() -> AnyClass + + /** + Return `YES` if an object should be created from `source`. Return `NO` to ignore and skip `source`. If not implemented, transactions assume `YES`. - parameter source: the object to import from - parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed. - - returns: `true` if an object should be created from `source`. Return `false` to ignore. + - returns: `YES` if an object should be created from `source`. Return `NO` to ignore. */ @objc - static func shouldInsertFromImportSource(source: AnyObject, inTransaction transaction: CSBaseDataTransaction) -> Bool + optional static func shouldInsertFromImportSource(source: AnyObject, inTransaction transaction: CSBaseDataTransaction) -> Bool /** - Implements the actual importing of data from `source`. Implementers should pull values from `source` and assign them to the receiver's attributes. Note that throwing from this method will cause subsequent imports that are part of the same `importObjects(:sourceArray:)` call to be cancelled. + Implements the actual importing of data from `source`. Implementers should pull values from `source` and assign them to the receiver's attributes. Note that throwing from this method will cause subsequent imports that are part of the same `-importObjects:sourceArray:` call to be cancelled. - parameter source: the object to import from - parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed. diff --git a/Sources/ObjectiveC/CSSaveResult.swift b/Sources/ObjectiveC/CSSaveResult.swift index 104f636..e21a980 100644 --- a/Sources/ObjectiveC/CSSaveResult.swift +++ b/Sources/ObjectiveC/CSSaveResult.swift @@ -36,7 +36,7 @@ import CoreData public final class CSSaveResult: NSObject, CoreStoreBridge { /** - `true` if the `commit` operation for the transaction succeeded, either because the save succeeded or because there were no changes to save. Returns `false` to indicate failure. + `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 { @@ -45,7 +45,7 @@ public final class CSSaveResult: NSObject, CoreStoreBridge { } /** - `true` if the `commit` operation for the transaction failed, or `false` otherwise. When `true`, the `error` property returns the actual `NSError` for the failure. + `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 { @@ -54,7 +54,7 @@ public final class CSSaveResult: NSObject, CoreStoreBridge { } /** - `true` if the `commit` operation for the transaction succeeded and if there was an actual change made. Returns `false` otherwise. + `YES` if the `commit` operation for the transaction succeeded and if there was an actual change made. Returns `NO` otherwise. */ @objc public var hasChanges: Bool { diff --git a/Sources/ObjectiveC/CSUnsafeDataTransaction.swift b/Sources/ObjectiveC/CSUnsafeDataTransaction.swift index 30a65b1..eb5e255 100644 --- a/Sources/ObjectiveC/CSUnsafeDataTransaction.swift +++ b/Sources/ObjectiveC/CSUnsafeDataTransaction.swift @@ -93,7 +93,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction { /** Begins a child transaction where `NSManagedObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms. - To support "undo" methods such as `-undo`, `-redo`, and `-rollback`, use the `-beginSafeWithSupportsUndo:` method passing `true` to the argument. Without "undo" support, calling those methods will raise an exception. + To support "undo" methods such as `-undo`, `-redo`, and `-rollback`, use the `-beginSafeWithSupportsUndo:` method passing `YES` to the argument. Without "undo" support, calling those methods will raise an exception. - returns: a `CSUnsafeDataTransaction` instance where creates, updates, and deletes can be made. */ @objc @@ -109,7 +109,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction { /** Begins a child transaction where `NSManagedObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms. - - prameter supportsUndo: `-undo`, `-redo`, and `-rollback` methods are only available when this parameter is `true`, otherwise those method will raise an exception. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited. + - prameter supportsUndo: `-undo`, `-redo`, and `-rollback` methods are only available when this parameter is `YES`, otherwise those method will raise an exception. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited. - returns: a `CSUnsafeDataTransaction` instance where creates, updates, and deletes can be made. */ @objc