File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Firestore/Swift/Source/AsyncAwait Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -42,4 +42,30 @@ public extension CollectionReference {
4242 }
4343 }
4444 }
45+
46+ /// Encodes an instance of `Encodable` and adds a new document to this collection
47+ /// with the encoded data, assigning it a document ID automatically.
48+ ///
49+ /// See `Firestore.Encoder` for more details about the encoding process.
50+ ///
51+ /// - Parameters:
52+ /// - value: An instance of `Encodable` to be encoded to a document.
53+ /// - encoder: An encoder instance to use to run the encoding.
54+ /// - Returns: A `DocumentReference` pointing to the newly created document.
55+ @discardableResult
56+ func addDocument< T: Encodable > ( from value: T ,
57+ encoder: Firestore . Encoder = Firestore . Encoder ( ) ) async throws
58+ -> DocumentReference {
59+ return try await withCheckedThrowingContinuation { continuation in
60+ var document : DocumentReference ?
61+ document = self . addDocument ( from: value, encoder: encoder) { error in
62+ if let error {
63+ continuation. resume ( throwing: error)
64+ } else {
65+ // Our callbacks guarantee that we either return an error or a document.
66+ continuation. resume ( returning: document!)
67+ }
68+ }
69+ }
70+ }
4571}
You can’t perform that action at this time.
0 commit comments