FirebaseFirestoreSwift Framework Reference
Stay organized with collections
Save and categorize content based on your preferences.
Transaction
public extension Transaction
-
Encodes an instance of Encodable
and overwrites the encoded data
to the document referred by doc
. If no document exists,
it is created. If a document already exists, it is overwritten.
See Firestore.Encoder
for more details about the encoding process.
Declaration
Swift
@discardableResult
func setData<T: Encodable>(from value: T,
forDocument doc: DocumentReference,
encoder: Firestore.Encoder = Firestore
.Encoder()) throws -> Transaction
Parameters
value
|
a instance of Encoded to be encoded to a document.
|
encoder
|
The encoder instance to use to run the encoding.
|
doc
|
The document to create/overwrite the encoded data to.
|
Return Value
This instance of Transaction
. Used for chaining method calls.
-
Encodes an instance of Encodable
and overwrites the encoded data
to the document referred by doc
. If no document exists,
it is created. If a document already exists, it is overwritten. If you pass
merge:true, the provided Encodable
will be merged into any existing document.
See Firestore.Encoder
for more details about the encoding process.
Declaration
Swift
@discardableResult
func setData<T: Encodable>(from value: T,
forDocument doc: DocumentReference,
merge: Bool,
encoder: Firestore.Encoder = Firestore
.Encoder()) throws -> Transaction
Parameters
value
|
An instance of Encodable to be encoded to a document.
|
doc
|
The document to create/overwrite the encoded data to.
|
merge
|
Whether to merge the provided Encodable into any existing
document.
|
encoder
|
The encoder instance to use to run the encoding.
|
Return Value
This instance of Transaction
. Used for chaining method calls.
-
Encodes an instance of Encodable
and writes the encoded data to the document referred
by doc
by only replacing 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
field in the Encodable
.
See Firestore.Encoder
for more details about the encoding process.
Declaration
Swift
@discardableResult
func setData<T: Encodable>(from value: T,
forDocument doc: DocumentReference,
mergeFields: [Any],
encoder: Firestore.Encoder = Firestore
.Encoder()) throws -> Transaction
Parameters
value
|
An instance of Encodable to be encoded to a document.
|
doc
|
The document to create/overwrite the encoded data to.
|
mergeFields
|
Array of String or FieldPath elements specifying which fields to
merge. Fields can contain dots to reference nested fields within the
document.
|
encoder
|
The encoder instance to use to run the encoding.
|
Return Value
This instance of Transaction
. Used for chaining method calls.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-05-11 UTC.
[null,null,["Last updated 2022-05-11 UTC."],[],[],null,["Transaction \n\n public extension Transaction\n\n- `\n ``\n ``\n `\n\n [setData(from:forDocument:encoder:)](#/s:So14FIRTransactionC22FirebaseFirestoreSwiftE7setData4from11forDocument7encoderABx_So20FIRDocumentReferenceCSo12FIRFirestoreCACE7EncoderVtKSERzlF)`\n ` \n Encodes an instance of `Encodable` and overwrites the encoded data\n to the document referred by `doc`. If no document exists,\n it is created. If a document already exists, it is overwritten.\n\n See [Firestore.Encoder](../Extensions/Firestore/Encoder.html) for more details about the encoding process. \n\n Declaration \n Swift \n\n @discardableResult\n func setData\u003cT: Encodable\u003e(from value: T,\n forDocument doc: DocumentReference,\n encoder: Firestore.Encoder = Firestore\n .Encoder()) throws -\u003e Transaction\n\n Parameters\n\n Return Value\n\n This instance of `Transaction`. Used for chaining method calls.\n- `\n ``\n ``\n `\n\n [setData(from:forDocument:merge:encoder:)](#/s:So14FIRTransactionC22FirebaseFirestoreSwiftE7setData4from11forDocument5merge7encoderABx_So20FIRDocumentReferenceCSbSo12FIRFirestoreCACE7EncoderVtKSERzlF)`\n ` \n Encodes an instance of `Encodable` and overwrites the encoded data\n to the document referred by `doc`. If no document exists,\n it is created. If a document already exists, it is overwritten. If you pass\n merge:true, the provided `Encodable` will be merged into any existing document.\n\n See [Firestore.Encoder](../Extensions/Firestore/Encoder.html) for more details about the encoding process. \n\n Declaration \n Swift \n\n @discardableResult\n func setData\u003cT: Encodable\u003e(from value: T,\n forDocument doc: DocumentReference,\n merge: Bool,\n encoder: Firestore.Encoder = Firestore\n .Encoder()) throws -\u003e Transaction\n\n Parameters\n\n Return Value\n\n This instance of `Transaction`. Used for chaining method calls.\n- `\n ``\n ``\n `\n\n [setData(from:forDocument:mergeFields:encoder:)](#/s:So14FIRTransactionC22FirebaseFirestoreSwiftE7setData4from11forDocument11mergeFields7encoderABx_So20FIRDocumentReferenceCSayypGSo12FIRFirestoreCACE7EncoderVtKSERzlF)`\n ` \n Encodes an instance of `Encodable` and writes the encoded data to the document referred\n by `doc` by only replacing the fields specified under `mergeFields`.\n Any field that is not specified in mergeFields is ignored and remains untouched. If the\n document doesn't yet exist, this method creates it and then sets the data.\n\n It is an error to include a field in `mergeFields` that does not have a corresponding\n field in the `Encodable`.\n\n See [Firestore.Encoder](../Extensions/Firestore/Encoder.html) for more details about the encoding process. \n\n Declaration \n Swift \n\n @discardableResult\n func setData\u003cT: Encodable\u003e(from value: T,\n forDocument doc: DocumentReference,\n mergeFields: [Any],\n encoder: Firestore.Encoder = Firestore\n .Encoder()) throws -\u003e Transaction\n\n Parameters\n\n Return Value\n\n This instance of `Transaction`. Used for chaining method calls."]]