mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-26 11:21:32 +01:00
WIP: CSImportableUniqueObject
This commit is contained in:
@@ -247,6 +247,7 @@
|
|||||||
B59851491C90289D00C99590 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; };
|
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 */; };
|
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 */; };
|
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 */; };
|
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 */; };
|
B59D5C221B5BA34B00453479 /* NSFileManager+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59D5C211B5BA34B00453479 /* NSFileManager+Setup.swift */; };
|
||||||
B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A261201B64BFDB006EB6D3 /* MigrationType.swift */; };
|
B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A261201B64BFDB006EB6D3 /* MigrationType.swift */; };
|
||||||
@@ -844,9 +845,9 @@
|
|||||||
children = (
|
children = (
|
||||||
B5DBE2CC1C9914A900B5CEFA /* CSCoreStore.swift */,
|
B5DBE2CC1C9914A900B5CEFA /* CSCoreStore.swift */,
|
||||||
B5519A491CA1F4FB002BEF78 /* CSError.swift */,
|
B5519A491CA1F4FB002BEF78 /* CSError.swift */,
|
||||||
B5E2222F1CA5339200BA2E95 /* Importing Data */,
|
|
||||||
B546F9611C9A13F400D5AC55 /* Setup */,
|
B546F9611C9A13F400D5AC55 /* Setup */,
|
||||||
B5519A5D1CA20093002BEF78 /* Saving and Processing */,
|
B5519A5D1CA20093002BEF78 /* Saving and Processing */,
|
||||||
|
B5E2222F1CA5339200BA2E95 /* Importing Data */,
|
||||||
B5E222211CA4DE5700BA2E95 /* Internal */,
|
B5E222211CA4DE5700BA2E95 /* Internal */,
|
||||||
);
|
);
|
||||||
path = ObjectiveC;
|
path = ObjectiveC;
|
||||||
@@ -1702,6 +1703,7 @@
|
|||||||
files = (
|
files = (
|
||||||
B5EA11DD1CA3AFD9002282F8 /* NSPersistentStoreCoordinator+Setup.swift in Sources */,
|
B5EA11DD1CA3AFD9002282F8 /* NSPersistentStoreCoordinator+Setup.swift in Sources */,
|
||||||
B5D9E2EF1CA2C317007A9D52 /* ObjectMonitor.swift in Sources */,
|
B5D9E2EF1CA2C317007A9D52 /* ObjectMonitor.swift in Sources */,
|
||||||
|
B59983491CA54BC100E1A417 /* CSBaseDataTransaction.swift in Sources */,
|
||||||
B5E2222B1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */,
|
B5E2222B1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */,
|
||||||
B5D9E2F01CA2C317007A9D52 /* CoreStoreFetchedResultsController.swift in Sources */,
|
B5D9E2F01CA2C317007A9D52 /* CoreStoreFetchedResultsController.swift in Sources */,
|
||||||
B5D9E3461CA2C6C4007A9D52 /* GCDQueue.swift in Sources */,
|
B5D9E3461CA2C6C4007A9D52 /* GCDQueue.swift in Sources */,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ private struct Static {
|
|||||||
SQLiteStore(
|
SQLiteStore(
|
||||||
fileName: "TimeZoneDemo.sqlite",
|
fileName: "TimeZoneDemo.sqlite",
|
||||||
configuration: "FetchingAndQueryingDemo",
|
configuration: "FetchingAndQueryingDemo",
|
||||||
resetStoreOnModelMismatch: true
|
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ private struct Static {
|
|||||||
SQLiteStore(
|
SQLiteStore(
|
||||||
fileName: "ColorsDemo.sqlite",
|
fileName: "ColorsDemo.sqlite",
|
||||||
configuration: "ObservingDemo",
|
configuration: "ObservingDemo",
|
||||||
resetStoreOnModelMismatch: true
|
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
GCDQueue.Main.async { [weak self] in
|
||||||
|
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ private struct Static {
|
|||||||
SQLiteStore(
|
SQLiteStore(
|
||||||
fileName: "AccountsDemo_FB_Male.sqlite",
|
fileName: "AccountsDemo_FB_Male.sqlite",
|
||||||
configuration: maleConfiguration,
|
configuration: maleConfiguration,
|
||||||
resetStoreOnModelMismatch: true
|
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
try! dataStack.addStorageAndWait(
|
try! dataStack.addStorageAndWait(
|
||||||
SQLiteStore(
|
SQLiteStore(
|
||||||
fileName: "AccountsDemo_FB_Female.sqlite",
|
fileName: "AccountsDemo_FB_Female.sqlite",
|
||||||
configuration: femaleConfiguration,
|
configuration: femaleConfiguration,
|
||||||
resetStoreOnModelMismatch: true
|
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,14 +60,14 @@ private struct Static {
|
|||||||
SQLiteStore(
|
SQLiteStore(
|
||||||
fileName: "AccountsDemo_TW_Male.sqlite",
|
fileName: "AccountsDemo_TW_Male.sqlite",
|
||||||
configuration: maleConfiguration,
|
configuration: maleConfiguration,
|
||||||
resetStoreOnModelMismatch: true
|
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
try! dataStack.addStorageAndWait(
|
try! dataStack.addStorageAndWait(
|
||||||
SQLiteStore(
|
SQLiteStore(
|
||||||
fileName: "AccountsDemo_TW_Female.sqlite",
|
fileName: "AccountsDemo_TW_Female.sqlite",
|
||||||
configuration: femaleConfiguration,
|
configuration: femaleConfiguration,
|
||||||
resetStoreOnModelMismatch: true
|
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ private struct Static {
|
|||||||
SQLiteStore(
|
SQLiteStore(
|
||||||
fileName: "PlaceDemo.sqlite",
|
fileName: "PlaceDemo.sqlite",
|
||||||
configuration: "TransactionsDemo",
|
configuration: "TransactionsDemo",
|
||||||
resetStoreOnModelMismatch: true
|
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -33,17 +33,25 @@ import CoreData
|
|||||||
public protocol CSImportableObject: class, AnyObject {
|
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 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.
|
- 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
|
@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 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.
|
- parameter transaction: the transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import CoreData
|
|||||||
public final class CSSaveResult: NSObject, CoreStoreBridge {
|
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
|
@objc
|
||||||
public var isSuccess: Bool {
|
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
|
@objc
|
||||||
public var isFailure: Bool {
|
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
|
@objc
|
||||||
public var hasChanges: Bool {
|
public var hasChanges: Bool {
|
||||||
|
|||||||
@@ -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.
|
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.
|
- returns: a `CSUnsafeDataTransaction` instance where creates, updates, and deletes can be made.
|
||||||
*/
|
*/
|
||||||
@objc
|
@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.
|
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.
|
- returns: a `CSUnsafeDataTransaction` instance where creates, updates, and deletes can be made.
|
||||||
*/
|
*/
|
||||||
@objc
|
@objc
|
||||||
|
|||||||
Reference in New Issue
Block a user