@@ -48,14 +48,18 @@ public extension DocumentReference {
48
48
/// not yet been set to their final value are returned from the snapshot.
49
49
/// - decoder: The decoder to use to convert the document. Defaults to use
50
50
/// the default decoder.
51
+ /// - source: Indicates whether the results should be fetched from the cache only
52
+ /// (`Source.cache`), the server only (`Source.server`), or to attempt the
53
+ /// server and fall back to the cache (`Source.default`).
51
54
/// - completion: The closure to call when the document snapshot has been
52
55
/// fetched and decoded.
53
56
func getDocument< T: Decodable > ( as type: T . Type ,
54
57
with serverTimestampBehavior: ServerTimestampBehavior =
55
58
. none,
56
59
decoder: Firestore . Decoder = . init( ) ,
60
+ source: FirestoreSource = . default,
57
61
completion: @escaping ( Result < T , Error > ) -> Void ) {
58
- getDocument { snapshot, error in
62
+ getDocument ( source : source ) { snapshot, error in
59
63
guard let snapshot = snapshot else {
60
64
/**
61
65
* Force unwrapping here is fine since this logic corresponds to the auto-synthesized
@@ -101,13 +105,17 @@ public extension DocumentReference {
101
105
/// snapshot.
102
106
/// - decoder: The decoder to use to convert the document. Defaults to use
103
107
/// the default decoder.
108
+ /// - source: Indicates whether the results should be fetched from the cache only
109
+ /// (`Source.cache`), the server only (`Source.server`), or to attempt the
110
+ /// server and fall back to the cache (`Source.default`).
104
111
/// - Returns: This instance of the supplied `Decodable` type `T`.
105
112
@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
106
113
func getDocument< T: Decodable > ( as type: T . Type ,
107
114
with serverTimestampBehavior: ServerTimestampBehavior =
108
115
. none,
109
- decoder: Firestore . Decoder = . init( ) ) async throws -> T {
110
- let snapshot = try await getDocument ( )
116
+ decoder: Firestore . Decoder = . init( ) ,
117
+ source: FirestoreSource = . default) async throws -> T {
118
+ let snapshot = try await getDocument ( source: source)
111
119
return try snapshot. data ( as: T . self,
112
120
with: serverTimestampBehavior,
113
121
decoder: decoder)
0 commit comments