mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-18 23:19:45 +02:00
expose DetachedDataTransaction's context and allow creating children detached transactions (https://github.com/JohnEstropia/CoreStore/issues/9)
This commit is contained in:
@@ -62,7 +62,7 @@ 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.
|
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.
|
||||||
|
|
||||||
- returns: a `DetachedDataTransaction` instance where creates, updates, and deletes can be made.
|
- returns: a `DetachedDataTransaction` instance where creates, updates, and deletes can be made.
|
||||||
*/
|
*/
|
||||||
@@ -70,6 +70,10 @@ public extension DataStack {
|
|||||||
|
|
||||||
return DetachedDataTransaction(
|
return DetachedDataTransaction(
|
||||||
mainContext: self.rootSavingContext,
|
mainContext: self.rootSavingContext,
|
||||||
queue: .Main)
|
queue: .createSerial(
|
||||||
|
"com.coreStore.dataStack.detachedTransactionQueue",
|
||||||
|
targetQueue: .UserInitiated
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,18 @@ public final class DetachedDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
// MARK: Public
|
// MARK: Public
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the `NSManagedObjectContext` for this detached transaction. Use only for cases where external frameworks need an `NSManagedObjectContext` instance to work with.
|
||||||
|
|
||||||
|
Note that it is the developer's responsibility to ensure the following:
|
||||||
|
- that the `DetachedDataTransaction` that owns this context should be strongly referenced and prevented from being deallocated during the context's lifetime
|
||||||
|
- that all saves will be done either through the `DetachedDataTransaction`'s `commit(...)` method, or by calling `save()` manually on the context, its parent, and all other ancestor contexts if there are any.
|
||||||
|
*/
|
||||||
|
public var internalContext: NSManagedObjectContext {
|
||||||
|
|
||||||
|
return self.context
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Saves the transaction changes asynchronously. For a `DetachedDataTransaction`, multiple commits are allowed, although it is the developer's responsibility to ensure a reasonable leeway to prevent blocking the main thread.
|
Saves the transaction changes asynchronously. For a `DetachedDataTransaction`, multiple commits are allowed, although it is the developer's responsibility to ensure a reasonable leeway to prevent blocking the main thread.
|
||||||
|
|
||||||
@@ -50,6 +62,19 @@ public final class DetachedDataTransaction: BaseDataTransaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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.
|
||||||
|
|
||||||
|
- returns: a `DetachedDataTransaction` instance where creates, updates, and deletes can be made.
|
||||||
|
*/
|
||||||
|
public func beginDetached() -> DetachedDataTransaction {
|
||||||
|
|
||||||
|
return DetachedDataTransaction(
|
||||||
|
mainContext: self.context,
|
||||||
|
queue: self.transactionQueue
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user