CSUnsafeDataTransaction
@objc
public final class CSUnsafeDataTransaction : CSBaseDataTransaction, CoreStoreObjectiveCType
The CSUnsafeDataTransaction
serves as the Objective-C bridging type for UnsafeDataTransaction
.
See also
UnsafeDataTransaction
-
Saves the transaction changes asynchronously. For a
CSUnsafeDataTransaction
, multiple commits are allowed, although it is the developer’s responsibility to ensure a reasonable leeway to prevent blocking the main thread.Declaration
Swift
@objc public func commitWithSuccess(_ success: (() -> Void)?, _ failure: ((CSError) -> Void)?)
Parameters
success
the block executed if the save succeeds.
failure
the block executed if the save fails. A
CSError
is reported as the argument of the block. -
Saves the transaction changes and waits for completion synchronously. For a
CSUnsafeDataTransaction
, multiple commits are allowed, although it is the developer’s responsibility to ensure a reasonable leeway to prevent blocking the main thread.Declaration
Swift
@objc public func commitAndWait(error: NSErrorPointer) -> Bool
Parameters
error
the
CSError
pointer that indicates the reason in case of an failureReturn Value
YES
if the commit succeeded,NO
if the commit failed. IfNO
, theerror
argument will hold error information. -
Rolls back the transaction.
Declaration
Swift
@objc public func rollback()
-
Undo’s the last change made to the transaction.
Declaration
Swift
@objc public func undo()
-
Redo’s the last undone change to the transaction.
Declaration
Swift
@objc public func redo()
-
Immediately flushes all pending changes to the transaction’s observers. This is useful in conjunction with
ListMonitor
s andObjectMonitor
s created fromUnsafeDataTransaction
s used to manage temporaryscratch
data.Important
Note that unlikecommit()
,flush()
does not propagate/save updates to theDataStack
and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. throughtransaction.beginUnsafe()
)Declaration
Swift
@objc public func flush()
-
Flushes all pending changes to the transaction’s observers at the end of the
closure
‘s execution. This is useful in conjunction withListMonitor
s andObjectMonitor
s created fromUnsafeDataTransaction
s used to manage temporaryscratch
data.Declaration
Swift
@objc public func flush(_ block: () -> Void)
Parameters
block
the block where changes can be made prior to the flush
-
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 passingYES
to the argument. Withoutundo
support, calling those methods will raise an exception.Declaration
Swift
@objc public func beginUnsafe() -> CSUnsafeDataTransaction
Return Value
a
CSUnsafeDataTransaction
instance where creates, updates, and deletes can be made. -
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 isYES
, 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.
Declaration
Swift
@objc public func beginUnsafeWithSupportsUndo(_ supportsUndo: Bool) -> CSUnsafeDataTransaction
Return Value
a
CSUnsafeDataTransaction
instance where creates, updates, and deletes can be made. - prameter supportsUndo:
-
Returns the
NSManagedObjectContext
for this unsafe transaction. Use only for cases where external frameworks need anNSManagedObjectContext
instance to work with.Note that it is the developer’s responsibility to ensure the following:
- that the
CSUnsafeDataTransaction
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
CSUnsafeDataTransaction
‘s-commit:
or-commitAndWait
method, or by calling-save:
manually on the context, its parent, and all other ancestor contexts if there are any.
Declaration
Swift
@objc public func unsafeContext() -> NSManagedObjectContext
- that the
-
Declaration
Swift
public typealias SwiftType = UnsafeDataTransaction
-
Declaration
Swift
public var bridgeToSwift: UnsafeDataTransaction { get }
-
Declaration
Swift
public required init(_ swiftValue: UnsafeDataTransaction)