SAI ANURAG
SAI ANURAG

Reputation: 31

How do I access the data from Cloud Firestore database in Firebase using Swift in Xcode?

I am new to Firebase and basically I want to access the elements in the documents that are the id fields in each of the documents and I want to loop through them, is there any way I can retrieve and put that data in some kind of array and later loop through the array in swift? I am new here in StackOverflow please don't mind if I didn't ask the question properly. The link to the image how my database looks like is below please go through it.

So this is how my CloudFirestore Database looks like

Upvotes: 0

Views: 451

Answers (1)

Atif Zia
Atif Zia

Reputation: 793

For This you have to setup Firebase Client SDK https://github.com/firebase/firebase-ios-sdk and after successfully setup

let db = Firestore.firestore()
        db.collection("UniqueId's").getDocuments { (snapshot, error) in
            if error != nil {
                print(error)
            } else {
                for document in (snapshot?.documents)! {
                    if let id = document.data()["id"] as? String {
                    //Here you'll get your data
                }
            }

By the way I think your collection name may be a problem So if it is than change it's name to UniqueIds instead of UniqueIds

Upvotes: 1

Related Questions