diff --git a/Sources/FirebaseFirestore/DocumentReference+Swift.swift b/Sources/FirebaseFirestore/DocumentReference+Swift.swift index fb0ff0c..0d347da 100644 --- a/Sources/FirebaseFirestore/DocumentReference+Swift.swift +++ b/Sources/FirebaseFirestore/DocumentReference+Swift.swift @@ -48,6 +48,7 @@ extension DocumentReference { future.Wait(firebase.FutureBase.kWaitTimeoutInfinite) } + guard snapshot.pointee.exists else { return nil } return snapshot.pointee.is_valid() ? snapshot.pointee : nil } diff --git a/Sources/FirebaseFirestore/DocumentSnapshot+Swift.swift b/Sources/FirebaseFirestore/DocumentSnapshot+Swift.swift index 5057d81..78c72dc 100644 --- a/Sources/FirebaseFirestore/DocumentSnapshot+Swift.swift +++ b/Sources/FirebaseFirestore/DocumentSnapshot+Swift.swift @@ -21,6 +21,10 @@ extension DocumentSnapshot { swift_firebase.swift_cxx_shims.firebase.firestore.snapshot_reference(self) } + public var exists: Bool { + swift_firebase.swift_cxx_shims.firebase.firestore.snapshot_exists(self) + } + public func data(with behavior: ServerTimestampBehavior) -> [String: Any]? { let data = swift_firebase.swift_cxx_shims.firebase.firestore.snapshot_get_data_workaround(self, behavior) return FirestoreDataConverter.value(workaround: data) diff --git a/Sources/firebase/include/FirebaseFirestore.hh b/Sources/firebase/include/FirebaseFirestore.hh index 722d826..543f3ee 100644 --- a/Sources/firebase/include/FirebaseFirestore.hh +++ b/Sources/firebase/include/FirebaseFirestore.hh @@ -64,6 +64,11 @@ snapshot_reference(const ::firebase::firestore::DocumentSnapshot snapshot) { return snapshot.reference(); } +inline bool +snapshot_exists(const ::firebase::firestore::DocumentSnapshot &snapshot) { + return snapshot.exists(); +} + #if SR69711 struct MapFieldValue_Workaround { std::vector keys;