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
successthe block executed if the save succeeds.
failurethe block executed if the save fails. A
CSErroris 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) -> BoolParameters
errorthe
CSErrorpointer that indicates the reason in case of an failureReturn Value
YESif the commit succeeded,NOif the commit failed. IfNO, theerrorargument 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
ListMonitors andObjectMonitors created fromUnsafeDataTransactions used to manage temporaryscratch
data.Important
Note that unlikecommit(),flush()does not propagate/save updates to theDataStackand 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 withListMonitors andObjectMonitors created fromUnsafeDataTransactions used to manage temporaryscratch
data.Declaration
Swift
@objc public func flush(_ block: () -> Void)Parameters
blockthe block where changes can be made prior to the flush
-
Begins a child transaction where
NSManagedObjectcreates, 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 passingYESto the argument. Withoutundo
support, calling those methods will raise an exception.Declaration
Swift
@objc public func beginUnsafe() -> CSUnsafeDataTransactionReturn Value
a
CSUnsafeDataTransactioninstance where creates, updates, and deletes can be made. -
Begins a child transaction where
NSManagedObjectcreates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms.- prameter supportsUndo:
-undo,-redo, and-rollbackmethods 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) -> CSUnsafeDataTransactionReturn Value
a
CSUnsafeDataTransactioninstance where creates, updates, and deletes can be made. - prameter supportsUndo:
-
Returns the
NSManagedObjectContextfor this unsafe transaction. Use only for cases where external frameworks need anNSManagedObjectContextinstance to work with.Note that it is the developer’s responsibility to ensure the following:
- that the
CSUnsafeDataTransactionthat 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-commitAndWaitmethod, 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)
View on GitHub
CSUnsafeDataTransaction Class Reference