-
-
Save byaruhaf/7a4c266a38d322b7b2f387b132682a50 to your computer and use it in GitHub Desktop.
FirebaseFirestore Query Snapshot listener to Result conversion wrapper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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