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:
- Avoid rebuilding the index for every individual operation, which would be very costly.
- 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]) throwsParameters
objectObject to save. It must contain an
objectIDattribute. -
Save an object.
Declaration
Swift
@discardableResult @objc public func saveObject(_ object: [String: Any], completionHandler: CompletionHandler? = nil) -> OperationParameters
objectObject to save. It must contain an
objectIDattribute.completionHandlerCompletion 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]]) throwsParameters
objectsNew versions of the objects to update. Each one must contain an
objectIDattribute. -
Save multiple objects.
Declaration
Swift
@discardableResult @objc public func saveObjects(_ objects: [[String: Any]], completionHandler: CompletionHandler? = nil) -> OperationParameters
objectsNew versions of the objects to update. Each one must contain an
objectIDattribute.completionHandlerCompletion 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) throwsParameters
objectIDIdentifier of the object to delete.
-
Delete an object.
Declaration
Swift
@discardableResult @objc public func deleteObject(withID objectID: String, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectIDIdentifier of the object to delete.
completionHandlerCompletion 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]) throwsParameters
objectIDsIdentifiers of the objects to delete.
-
Delete multiple objects.
Declaration
Swift
@discardableResult @objc public func deleteObjects(withIDs objectIDs: [String], completionHandler: CompletionHandler? = nil) -> OperationParameters
objectIDsIdentifiers of the objects to delete.
completionHandlerCompletion 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]) throwsParameters
settingsNew 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) -> OperationParameters
settingsNew settings.
completionHandlerCompletion 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) -> OperationParameters
completionHandlerCompletion 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) -> OperationParameters
completionHandlerCompletion 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) -> OperationParameters
completionHandlerCompletion handler to be notified when the transaction has been rolled back.
Return Value
The corresponding operation.
WriteTransaction Class Reference