urban-health-labs / CombineFirebase

Combine wrapper on Google's iOS Firebase library.
MIT License
225 stars 44 forks source link

Cannot find publish() function #21

Open kencoken opened 3 years ago

kencoken commented 3 years ago

Apologies if am missing something as a bit of a Combine novice. I have installed CombineFirebase 0.3.0 and Firebase 7.11.1 and am trying to follow the example from the readme file for listening to a collection in Firestore:

import CombineFirebase
import Firebase
import Combine

let db = Firestore.firestore()
var cancelBag = Set<Cancellable>()

func listenCollection() {
    db.collection("cities")
        .publisher()
        .sink(receiveCompletion: { completion in
            switch completion {
            case .finished: print("🏁 finished")
            case .failure(let error): print("❗️ failure: \(error)")
            }
        }) { snapshot in
            print("collection data: \(snapshot.documents)")
        }.store(in: &cancelBag)
}

However, Swift is unable to find the publisher() method on db.collection("cities") with only a:

publisher(for keyPath: KeyPath<CollectionReference, Value>)

I can see this exists on the Query object on the source code here so am unsure why db.collection("cities") which returns a CollectionReference (which derives from Query) can not find this definition.

kencoken commented 3 years ago

I can further confirm that this only happens when I install the package using the Swift Package Manager and not CocoaPods.

If importing the relevant sub-package directly then the compilation works:

import CombineFirebaseFirestore

So it seems that something is going wrong with the global import.

kshivang commented 2 years ago

Yes you are right, import issue is there with SPM version, you have to use respective module import as of now, new PR is welcomed on this.