Stay organized with collections
Save and categorize content based on your preferences.
DocumentSnapshot
classDocumentSnapshot:NSObject,@uncheckedSendable
A DocumentSnapshot contains data read from a document in your Firestore database. The data
can be extracted with the data property or by using subscript syntax to access a specific
field.
For a DocumentSnapshot that points to a non-existing document, any data access will return
nil. You can use the exists property to explicitly verify a documents existence.
Retrieves all fields in the document as a Dictionary. Returns nil if the document doesn’t
exist.
Server-provided timestamps that have not yet been set to their final value will be returned as
NSNull. You can use the data(with:) method to configure this behavior.
Declaration
Swift
funcdata()->[String:Any]?
Return Value
A Dictionary containing all fields in the document or nil if the document doesn’t
exist.
Retrieves a specific field from the document. Returns nil if the document or the field doesn’t
exist.
The timestamps that have not yet been set to their final value will be returned as NSNull. You
can use get(_:serverTimestampBehavior:) to configure this behavior.
Declaration
Swift
funcget(_field:Any)->Any?
Parameters
field
The field to retrieve.
Return Value
The value contained in the field or nil if the document or field doesn’t exist.
Retrieves a specific field from the document. Returns nil if the document or the field doesn’t
exist.
The timestamps that have not yet been set to their final value will be returned as NSNull. You
can use get(_:serverTimestampBehavior:) to configure this behavior.
Retrieves all fields in a document and converts them to an instance of
caller-specified type.
By default, server-provided timestamps that have not yet been set to their
final value will be returned as NSNull. Pass serverTimestampBehavior
to configure this behavior.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-11 UTC."],[],[],null,["# FirebaseFirestore Framework Reference\n\nDocumentSnapshot\n================\n\n class DocumentSnapshot : NSObject, @unchecked Sendable\n\nA `DocumentSnapshot` contains data read from a document in your Firestore database. The data\ncan be extracted with the `data` property or by using subscript syntax to access a specific\nfield.\n\nFor a `DocumentSnapshot` that points to a non-existing document, any data access will return\n`nil`. You can use the `exists` property to explicitly verify a documents existence.\n- `\n ``\n ``\n `\n\n ### [exists](#/c:objc(cs)FIRDocumentSnapshot(py)exists)\n\n `\n ` \n True if the document exists. \n\n #### Declaration\n\n Swift \n\n var exists: Bool { get }\n\n- `\n ``\n ``\n `\n\n ### [reference](#/c:objc(cs)FIRDocumentSnapshot(py)reference)\n\n `\n ` \n A [DocumentReference](../Classes/DocumentReference.html) to the document location. \n\n #### Declaration\n\n Swift \n\n var reference: FIRDocumentReference { get }\n\n- `\n ``\n ``\n `\n\n ### [documentID](#/c:objc(cs)FIRDocumentSnapshot(py)documentID)\n\n `\n ` \n The ID of the document for which this `DocumentSnapshot` contains data. \n\n #### Declaration\n\n Swift \n\n var documentID: String { get }\n\n- `\n ``\n ``\n `\n\n ### [metadata](#/c:objc(cs)FIRDocumentSnapshot(py)metadata)\n\n `\n ` \n Metadata about this snapshot concerning its source and if it has local modifications. \n\n #### Declaration\n\n Swift \n\n var metadata: FIRSnapshotMetadata { get }\n\n- `\n ``\n ``\n `\n\n ### [data()](#/c:objc(cs)FIRDocumentSnapshot(im)data)\n\n `\n ` \n Retrieves all fields in the document as a `Dictionary`. Returns `nil` if the document doesn't\n exist.\n\n Server-provided timestamps that have not yet been set to their final value will be returned as\n `NSNull`. You can use the [data(with:)](../Classes/DocumentSnapshot.html#/c:objc(cs)FIRDocumentSnapshot(im)dataWithServerTimestampBehavior:) method to configure this behavior. \n\n #### Declaration\n\n Swift \n\n func data() -\u003e [String : Any]?\n\n #### Return Value\n\n A `Dictionary` containing all fields in the document or `nil` if the document doesn't\n exist.\n- `\n ``\n ``\n `\n\n ### [data(with:)](#/c:objc(cs)FIRDocumentSnapshot(im)dataWithServerTimestampBehavior:)\n\n `\n ` \n Retrieves all fields in the document as a `Dictionary`. Returns `nil` if the document doesn't\n exist. \n\n #### Declaration\n\n Swift \n\n func data(with serverTimestampBehavior: ../Enums/ServerTimestampBehavior.html) -\u003e [String : Any]?\n\n #### Parameters\n\n |---------------------------------|------------------------------------------------------------------------------------------------------------------|\n | ` `*serverTimestampBehavior*` ` | Configures how server timestamps that have not yet been set to their final value are returned from the snapshot. |\n\n #### Return Value\n\n A `Dictionary` containing all fields in the document or `nil` if the document doesn't\n exist.\n- `\n ``\n ``\n `\n\n ### [get(_:)](#/c:objc(cs)FIRDocumentSnapshot(im)valueForField:)\n\n `\n ` \n Retrieves a specific field from the document. Returns `nil` if the document or the field doesn't\n exist.\n\n The timestamps that have not yet been set to their final value will be returned as `NSNull`. You\n can use [get(_:serverTimestampBehavior:)](../Classes/DocumentSnapshot.html#/c:objc(cs)FIRDocumentSnapshot(im)valueForField:serverTimestampBehavior:) to configure this behavior. \n\n #### Declaration\n\n Swift \n\n func get(_ field: Any) -\u003e Any?\n\n #### Parameters\n\n |---------------|------------------------|\n | ` `*field*` ` | The field to retrieve. |\n\n #### Return Value\n\n The value contained in the field or `nil` if the document or field doesn't exist.\n- `\n ``\n ``\n `\n\n ### [get(_:serverTimestampBehavior:)](#/c:objc(cs)FIRDocumentSnapshot(im)valueForField:serverTimestampBehavior:)\n\n `\n ` \n Retrieves a specific field from the document. Returns `nil` if the document or the field doesn't\n exist.\n\n The timestamps that have not yet been set to their final value will be returned as `NSNull`. You\n can use `get(_:serverTimestampBehavior:)` to configure this behavior. \n\n #### Declaration\n\n Swift \n\n func get(_ field: Any, serverTimestampBehavior: ../Enums/ServerTimestampBehavior.html) -\u003e Any?\n\n #### Parameters\n\n |---------------------------------|------------------------------------------------------------------------------------------------------------------|\n | ` `*field*` ` | The field to retrieve. |\n | ` `*serverTimestampBehavior*` ` | Configures how server timestamps that have not yet been set to their final value are returned from the snapshot. |\n\n #### Return Value\n\n The value contained in the field or `nil` if the document or field doesn't exist.\n- `\n ``\n ``\n `\n\n ### [subscript(_:)](#/c:objc(cs)FIRDocumentSnapshot(im)objectForKeyedSubscript:)\n\n `\n ` \n Retrieves a specific field from the document. \n\n #### Declaration\n\n Swift \n\n subscript(key: Any) -\u003e Any? { get }\n\n #### Parameters\n\n |-------------|------------------------|\n | ` `*key*` ` | The field to retrieve. |\n\n #### Return Value\n\n The value contained in the field or `nil` if the document or field doesn't exist.\n- `\n ``\n ``\n `\n\n ### [data(as:with:decoder:)](#/s:So19FIRDocumentSnapshotC17FirebaseFirestoreE4data2as4with7decoderxxm_So26FIRServerTimestampBehaviorVSo12FIRFirestoreCACE7DecoderCtKSeRzlF)\n\n `\n ` \n Retrieves all fields in a document and converts them to an instance of\n caller-specified type.\n\n By default, server-provided timestamps that have not yet been set to their\n final value will be returned as `NSNull`. Pass `serverTimestampBehavior`\n to configure this behavior.\n\n See [Firestore.Decoder](../Classes/Firestore/Decoder.html) for more details about the decoding process. \n\n #### Declaration\n\n Swift \n\n func data\u003cT: Decodable\u003e(as type: T.Type,\n with serverTimestampBehavior: ../Enums/ServerTimestampBehavior.html = .none,\n decoder: ../Classes/Firestore.html.Decoder = .init()) throws -\u003e T"]]