Open CureleaAndrei opened 4 years ago
Actually that is already build in, you have to dig little more in docs.
Few bits:
var cityDocumentSnapshotMapper: (DocumentSnapshot) throws -> City? {
{
var city = try $0.data(as: City.self)
city.id = $0.documentID
return city
}
}
func listenDocumentAsObject() {
db.collection("cities")
.document("SF")
.publisher(as: City.self, documentSnapshotMapper: cityDocumentSnapshotMapper)
.sink(receiveCompletion: { completion in
switch completion {
case .finished: print("🏁 finished")
case .failure(let error): print("❗️ failure: \(error)")
}
}) { city in
print("City: \(city)")
}
.store(in: &cancelBag)
}
Hi, thanks for the quick reply. I've found this, but this is for firestore database, i meant that would be nice to have this also for the firebase realtime database. If there is also for real time database, my bad. I will look again into docs.
Thank you for pointing out, that functionality is missing. For now you can simply use combine .map, will surely add that feature in the future. PR is also welcome.
@CureleaAndrei you could do this with https://github.com/alickbass/CodableFirebase
Hi, awesome job on this library, I will use it in my projects. It will be awesome to have the mapper functionality for firebase database snapshot, also build in.