Skip to content

Instantly share code, notes, and snippets.

@byaruhaf
Forked from yimajo/Query+Result.swift
Created June 28, 2023 01:19
Show Gist options
  • Save byaruhaf/7a4c266a38d322b7b2f387b132682a50 to your computer and use it in GitHub Desktop.
Save byaruhaf/7a4c266a38d322b7b2f387b132682a50 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