WriteTransaction

@objcMembers
public class WriteTransaction : NSObject

A transaction to update the index.

A transaction gathers all the operations that will be performed when the transaction is committed. Its purpose is twofold:

  1. Avoid rebuilding the index for every individual operation, which would be very costly.
  2. Avoid keeping all the necessary data in memory, e.g. by flushing added objects to temporary files on disk.

A transaction can be created by calling OfflineIndex.newTransaction().

  • The index on which this transaction will operate.

    Declaration

    Swift

    @objc
    public let index: OfflineIndex
  • This transaction’s ID. Unique within the context of index. Not guaranteed to be unique across all indices.

    Declaration

    Swift

    @objc
    public let identifier: Int
  • Whether this transaction has completed (committed or rolled back).

    Declaration

    Swift

    @objc
    public private(set) var finished: Bool
  • Save an object (synchronously).

    Declaration

    Swift

    @objc
    public func saveObjectSync(_ object: [String : Any]) throws

    Parameters

    object

    Object to save. It must contain an objectID attribute.

  • Save an object.

    Declaration

    Swift

    @discardableResult
    @objc
    public func saveObject(_ object: [String: Any], completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    object

    Object to save. It must contain an objectID attribute.

    completionHandler

    Completion handler to be notified when the transaction has been updated.

    Return Value

    The corresponding operation.

  • Save multiple objects (synchronously).

    Declaration

    Swift

    @objc
    public func saveObjectsSync(_ objects: [[String : Any]]) throws

    Parameters

    objects

    New versions of the objects to update. Each one must contain an objectID attribute.

  • Save multiple objects.

    Declaration

    Swift

    @discardableResult
    @objc
    public func saveObjects(_ objects: [[String: Any]], completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    objects

    New versions of the objects to update. Each one must contain an objectID attribute.

    completionHandler

    Completion handler to be notified when the transaction has been updated.

    Return Value

    The corresponding operation.

  • Delete an object (synchronously).

    Declaration

    Swift

    @objc
    public func deleteObjectSync(withID objectID: String) throws

    Parameters

    objectID

    Identifier of the object to delete.

  • Delete an object.

    Declaration

    Swift

    @discardableResult
    @objc
    public func deleteObject(withID objectID: String, completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    objectID

    Identifier of the object to delete.

    completionHandler

    Completion handler to be notified when the transaction has been updated.

    Return Value

    The corresponding operation.

  • Delete multiple objects (synchronously).

    Declaration

    Swift

    @objc
    public func deleteObjectsSync(withIDs objectIDs: [String]) throws

    Parameters

    objectIDs

    Identifiers of the objects to delete.

  • Delete multiple objects.

    Declaration

    Swift

    @discardableResult
    @objc
    public func deleteObjects(withIDs objectIDs: [String], completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    objectIDs

    Identifiers of the objects to delete.

    completionHandler

    Completion handler to be notified when the transaction has been updated.

    Return Value

    The corresponding operation.

  • Set the index’s settings (synchronously).

    Please refer to our API documentation for the list of supported settings.

    Declaration

    Swift

    @objc
    public func setSettingsSync(_ settings: [String : Any]) throws

    Parameters

    settings

    New settings.

  • Set the index’s settings.

    Please refer to our API documentation for the list of supported settings.

    Declaration

    Swift

    @discardableResult
    @objc
    public func setSettings(_ settings: [String: Any], completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    settings

    New settings.

    completionHandler

    Completion handler to be notified when the transaction has been updated.

    Return Value

    The corresponding operation.

  • Delete the index content without removing settings (synchronously).

    Declaration

    Swift

    @objc
    public func clearIndexSync() throws
  • Delete the index content without removing settings.

    Declaration

    Swift

    @discardableResult
    @objc(clearIndex:)
    public func clearIndex(completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    completionHandler

    Completion handler to be notified when the transaction has been updated.

    Return Value

    The corresponding operation.

  • Commit the transaction (synchronously).

    Declaration

    Swift

    @objc
    public func commitSync() throws
  • Commit the transaction.

    Declaration

    Swift

    @discardableResult
    @objc(commit:)
    public func commit(completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    completionHandler

    Completion handler to be notified when the transaction has been committed.

    Return Value

    The corresponding operation.

  • Rollback the transaction (synchronously). The index will be left untouched.

    Declaration

    Swift

    @objc
    public func rollbackSync()
  • Rollback the transaction. The index will be left untouched.

    Declaration

    Swift

    @discardableResult
    @objc(rollback:)
    public func rollback(completionHandler: CompletionHandler? = nil) -> Operation

    Parameters

    completionHandler

    Completion handler to be notified when the transaction has been rolled back.

    Return Value

    The corresponding operation.