looking for some solutions? You are welcome.

SOLVED: Accessing a specific document field with Swift (Firestore)

JP89:

I have the following method that works really well, but I'm confused as to how I can actually retrieve a specific field from a document. I seem to only be able to reference document.data() which returns the entire document object.

I am trying to reference a specific field called "content" which is a String type in my Firestore.

Any guidance much appreciated!

let db = Firestore.firestore()
        db.collection("messages").whereField("channel", isEqualTo: "channel-name")
            .getDocuments() { (querySnapshot, err) in
                if let err = err {
                    print("Error getting documents: \(err)")
                } else {
                    for document in querySnapshot!.documents {
                        print("\(document.documentID) => \(document.data())")
                        let content = document.data() # Here I'd like to get the string attribute "content" from each document
                    }
                }
        }



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent