firebase-ios-sdk
firebase-ios-sdk copied to clipboard
Experimental support for AsyncSequence on Firestore snapshot listeners
This PR adds support for using Swift's AsyncSequence
to listen to changes on Firestore collections and documents.
Here is how to use it:
Listening to updates on a single document
let doc = Firestore.firestore().collection("fruits").document("1uxSAlCvYWmfrXN7rn2s")
for try await fruit in doc.snapshotSequence(Fruit.self) {
print(fruit.name)
}
Listening to updates on a collection
let collection = Firestore.firestore().collection("fruits")
for try await fruits in collection.snapshotSequence(Fruit.self) {
print(fruits.count)
}
See Example/FirestoreSample/FirestoreSample/Views/FavouriteFruitsAsyncSequenceView.swift
and Example/FirestoreSample/FirestoreSample/Views/FavouriteFruitView.swift
for more complete examples how to use this.
1 Warning | |
---|---|
:warning: | Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.) |
Generated by :no_entry_sign: Danger
Apple API Diff Report
Commit: f9781a01d5852c4c906a94b42f02fe527b5c4750 Last updated: Fri Jul 7 04:30 PDT 2023 View workflow logs & download artifacts
FirebaseFirestoreSwift
Extensions
[ADDED] Query
[ADDED] Query
Swift:
+ public extension Query
+ func snapshotSequence < T > ( _ type : T . Type , includeMetadataChanges : Bool = false ) -> AsyncThrowingStream < [ T ], Error > where T : Decodable
[MODIFIED] DocumentReference
[MODIFIED] DocumentReference
Swift:
+ public extension DocumentReference extension DocumentReference : DocumentIDWrappable
- extension DocumentReference : DocumentIDWrappable
+ func snapshotSequence < T > ( _ type : T . Type , includeMetadataChanges : Bool = false ) -> AsyncThrowingStream < T , Error > where T : Decodable
Coverage Report 1
Affected Products
FirebaseFirestore-iOS-FirebaseFirestore.framework
Overall coverage changed from 88.11% (cc3ed01) to 88.04% (f9781a0) by -0.07%.
Filename Base (cc3ed01) Merge (f9781a0) Diff exception.cc 84.21% 23.68% -60.53% leveldb_key.cc 98.14% 98.82% +0.69% leveldb_remote_document_cache.cc 96.41% 94.61% -1.80% ordered_code.cc 93.90% 94.39% +0.49% FirebaseFirestore-iOS-FirebaseFirestoreSwift.framework
Overall coverage changed from 40.79% (cc3ed01) to 36.78% (f9781a0) by -4.02%.
Filename Base (cc3ed01) Merge (f9781a0) Diff DocumentReference+AsyncStream.swift ? 0.00% ? Query+AsyncStream.swift ? 0.00% ?
Test Logs
It could also make sense to have a similar abstraction for a document rather than a query.
It could also make sense to have a similar abstraction for a document rather than a query.
Good point. Added!
Looks likes you might have had an out of date auth-swift
branch. It's been rebased a few times.
Please close, merge, or comment. We plan to close stale PRs on November 28, 2023.
I'd like to land this in Q4. Will rebase on the latest auth-swift
branch.