Skip to content

Instantly share code, notes, and snippets.

@yimajo
Created January 23, 2023 06:59
Show Gist options
  • Save yimajo/eb03e3f99b78e6fc05ec838ccbd677bc to your computer and use it in GitHub Desktop.
Save yimajo/eb03e3f99b78e6fc05ec838ccbd677bc to your computer and use it in GitHub Desktop.
FirebaseFirestore Query Snapshot listener to Result conversion wrapper.
import FirebaseFirestore
@available(swift 5.0)
public extension Query {
func addSnapshotListener(
includeMetadataChanges: Bool = false,
listener: @escaping (Result<QuerySnapshot, Error>) -> ()
) -> some ListenerRegistration {
addSnapshotListener(includeMetadataChanges: includeMetadataChanges) { snapshot, error in
if let error {
listener(.failure(error))
} else {
listener(.success(snapshot!))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment