Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirebaseDatabase Snapshot to custom object #7

Open
CureleaAndrei opened this issue Jun 14, 2020 · 4 comments
Open

FirebaseDatabase Snapshot to custom object #7

CureleaAndrei opened this issue Jun 14, 2020 · 4 comments
Labels
feature request Pull requests are welcome

Comments

@CureleaAndrei
Copy link

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.

@kshivang
Copy link
Collaborator

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)
}

@CureleaAndrei
Copy link
Author

CureleaAndrei commented Jun 14, 2020

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.

@kshivang
Copy link
Collaborator

kshivang commented Jun 14, 2020

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.

@kshivang kshivang added the feature request Pull requests are welcome label Jun 14, 2020
@ericlewis
Copy link

@CureleaAndrei you could do this with https://github.com/alickbass/CodableFirebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Pull requests are welcome
Projects
None yet
Development

No branches or pull requests

3 participants