migration utilities (beta)

This commit is contained in:
John Rommel Estropia
2015-07-07 07:58:16 +09:00
parent 261c3a6001
commit bf0eebe057
7 changed files with 748 additions and 458 deletions

View File

@@ -37,11 +37,14 @@ public extension DataStack {
/**
Begins a transaction asynchronously where `NSManagedObject` creates, updates, and deletes can be made.
:param: closure the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`.
- parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`.
*/
public func beginAsynchronous(closure: (transaction: AsynchronousDataTransaction) -> Void) {
CoreStore.assert(NSThread.isMainThread(), "Attempted to begin a transaction from a \(typeName(self)) outside the main thread.")
CoreStore.assert(
NSThread.isMainThread(),
"Attempted to begin a transaction from a \(typeName(self)) outside the main thread."
)
AsynchronousDataTransaction(
mainContext: self.rootSavingContext,
@@ -52,12 +55,15 @@ public extension DataStack {
/**
Begins a transaction synchronously where `NSManagedObject` creates, updates, and deletes can be made.
:param: closure the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`.
:returns: a `SaveResult` value indicating success or failure, or `nil` if the transaction was not comitted synchronously
- parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`.
- returns: a `SaveResult` value indicating success or failure, or `nil` if the transaction was not comitted synchronously
*/
public func beginSynchronous(closure: (transaction: SynchronousDataTransaction) -> Void) -> SaveResult? {
CoreStore.assert(NSThread.isMainThread(), "Attempted to begin a transaction from a \(typeName(self)) outside the main thread.")
CoreStore.assert(
NSThread.isMainThread(),
"Attempted to begin a transaction from a \(typeName(self)) outside the main thread."
)
return SynchronousDataTransaction(
mainContext: self.rootSavingContext,
@@ -68,11 +74,14 @@ public extension DataStack {
/**
Begins a non-contiguous transaction where `NSManagedObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms. A detached transaction object should typically be only used from the main queue.
:returns: a `DetachedDataTransaction` instance where creates, updates, and deletes can be made.
- returns: a `DetachedDataTransaction` instance where creates, updates, and deletes can be made.
*/
public func beginDetached() -> DetachedDataTransaction {
CoreStore.assert(NSThread.isMainThread(), "Attempted to begin a transaction from a \(typeName(self)) outside the main thread.")
CoreStore.assert(
NSThread.isMainThread(),
"Attempted to begin a transaction from a \(typeName(self)) outside the main thread."
)
return DetachedDataTransaction(
mainContext: self.rootSavingContext,