CSUnsafeDataTransaction

@objc
public final class CSUnsafeDataTransaction : CSBaseDataTransaction, CoreStoreObjectiveCType

The CSUnsafeDataTransaction serves as the Objective-C bridging type for 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 failure

    Return Value

    YES if the commit succeeded, NO if the commit failed. If NO, the error 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 ListMonitors and ObjectMonitors created from UnsafeDataTransactions used to manage temporary scratch data.

    Important

    Note that unlike commit(), flush() does not propagate/save updates to the DataStack and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. through transaction.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 with ListMonitors and ObjectMonitors created from UnsafeDataTransactions used to manage temporary scratch data.

    Important

    Note that unlike commit(), flush() does not propagate/save updates to the DataStack and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. through transaction.beginUnsafe())

    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 passing YES to the argument. Without undo 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 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.

    Declaration

    Swift

    @objc
    public func beginUnsafeWithSupportsUndo(_ supportsUndo: Bool) -> CSUnsafeDataTransaction

    Return Value

    a CSUnsafeDataTransaction instance where creates, updates, and deletes can be made.

  • Returns the NSManagedObjectContext for this unsafe 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 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