FIRWriteBatch


@interface FIRWriteBatch : NSObject

A write batch is used to perform multiple writes as a single atomic unit.

A WriteBatch object can be acquired by calling [FIRFirestore batch]. It provides methods for adding writes to the write batch. None of the writes will be committed (or visible locally) until [FIRWriteBatch commit] is called.

Unlike transactions, write batches are persisted offline and therefore are preferable when you don’t need to condition your writes on read data.

  • Writes to the document referred to by document. If the document doesn’t yet exist, this method creates it and then sets the data. If the document exists, this method overwrites the document data with the new values.

    Declaration

    Swift

    func setData(_ data: [String : Any], forDocument document: FIRDocumentReference) -> WriteBatch

    Objective-C

    - (nonnull FIRWriteBatch *)setData:(nonnull NSDictionary<NSString *, id> *)data
                           forDocument:(nonnull FIRDocumentReference *)document;

    Parameters

    data

    An NSDictionary that contains the fields and data to write to the document.

    document

    A reference to the document whose data should be overwritten.

    Return Value

    This FIRWriteBatch instance. Used for chaining method calls.

  • Writes to the document referred to by document. If the document doesn’t yet exist, this method creates it and then sets the data. If you pass FIRSetOptions, the provided data will be merged into an existing document.

    Declaration

    Swift

    func setData(_ data: [String : Any], forDocument document: FIRDocumentReference, options: FIRSetOptions) -> WriteBatch

    Objective-C

    - (nonnull FIRWriteBatch *)setData:(nonnull NSDictionary<NSString *, id> *)data
                           forDocument:(nonnull FIRDocumentReference *)document
                               options:(nonnull FIRSetOptions *)options;

    Parameters

    data

    An NSDictionary that contains the fields and data to write to the document.

    document

    A reference to the document whose data should be overwritten.

    options

    A FIRSetOptions used to configure the set behavior.

    Return Value

    This FIRWriteBatch instance. Used for chaining method calls.

  • Updates fields in the document referred to by document. If document does not exist, the write batch will fail.

    Declaration

    Swift

    func updateData(_ fields: [AnyHashable : Any], forDocument document: FIRDocumentReference) -> WriteBatch

    Objective-C

    - (nonnull FIRWriteBatch *)updateData:(nonnull NSDictionary<id, id> *)fields
                              forDocument:(nonnull FIRDocumentReference *)document;

    Parameters

    fields

    An NSDictionary containing the fields (expressed as an NSString or FIRFieldPath) and values with which to update the document.

    document

    A reference to the document whose data should be updated.

    Return Value

    This FIRWriteBatch instance. Used for chaining method calls.

  • Deletes the document referred to by document.

    Declaration

    Swift

    func deleteDocument(_ document: FIRDocumentReference) -> WriteBatch

    Objective-C

    - (nonnull FIRWriteBatch *)deleteDocument:
        (nonnull FIRDocumentReference *)document;

    Parameters

    document

    A reference to the document that should be deleted.

    Return Value

    This FIRWriteBatch instance. Used for chaining method calls.

  • Commits all of the writes in this write batch as a single atomic unit.

    Declaration

    Swift

    func commit(completion: @escaping (Error?) -> Void)

    Objective-C

    - (void)commitWithCompletion:(nonnull void (^)(NSError *_Nullable))completion;

    Parameters

    completion

    A block to be called once all of the writes in the batch have been successfully written to the backend as an atomic unit.