FirebaseFirestore Framework Reference

FIRTransaction


@interface FIRTransaction : NSObject

Transaction provides methods to read and write data within a transaction.

See

Firestore.runTransaction(_:)
  • 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

    Objective-C

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

    Parameters

    data

    A Dictionary 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 Transaction 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 merge:true, the provided data will be merged into any existing document.

    Declaration

    Objective-C

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

    Parameters

    data

    A Dictionary that contains the fields and data to write to the document.

    document

    A reference to the document whose data should be overwritten.

    merge

    Whether to merge the provided data into any existing document. If enabled, all omitted fields remain untouched. If your input sets any field to an empty dictionary, any nested field is overwritten.

    Return Value

    This Transaction instance. Used for chaining method calls.

  • Writes to the document referred to by document and only replace the fields specified under mergeFields. Any field that is not specified in mergeFields is ignored and remains untouched. If the document doesn’t yet exist, this method creates it and then sets the data.

    It is an error to include a field in mergeFields that does not have a corresponding value in the data dictionary.

    Declaration

    Objective-C

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

    Parameters

    data

    A Dictionary containing the fields that make up the document to be written.

    document

    A reference to the document whose data should be overwritten.

    mergeFields

    An Array that contains a list of String or FieldPath elements specifying which fields to merge. Fields can contain dots to reference nested fields within the document. If your input sets any field to an empty dictionary, any nested field is overwritten.

    Return Value

    This Transaction instance. Used for chaining method calls.

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

    Declaration

    Objective-C

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

    Parameters

    fields

    A Dictionary containing the fields (expressed as an String or FieldPath) and values with which to update the document.

    document

    A reference to the document whose data should be updated.

    Return Value

    This Transaction instance. Used for chaining method calls.

  • Deletes the document referred to by document.

    Declaration

    Objective-C

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

    Parameters

    document

    A reference to the document that should be deleted.

    Return Value

    This Transaction instance. Used for chaining method calls.

  • Reads the document referenced by document.

    Declaration

    Objective-C

    - (FIRDocumentSnapshot *_Nullable)
        getDocument:(nonnull FIRDocumentReference *)document
              error:(NSError *_Nullable *_Nullable)error;

    Parameters

    document

    A reference to the document to be read.

    error

    An out parameter to capture an error, if one occurred.