Created
January 23, 2023 06:59
-
-
Save yimajo/eb03e3f99b78e6fc05ec838ccbd677bc to your computer and use it in GitHub Desktop.
FirebaseFirestore Query Snapshot listener to Result conversion wrapper.
This file contains 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