[Swift] Get document Id as well as document in Cloud Firestore

db

{
  "people": {
    "-MPRm-8iCWsKK6B_nuHA": {
      "age": 30,
      "mail": "[email protected]",
      "name": "taro"
    },
  }
}

swift

let ref = Firestore.firestore().collection("people")

ref.getDocuments { (querySnapshot, error) in
    if let querySnapshot = querySnapshot {
        for document in querySnapshot.documents {
            let id = document.documentID
            let name = document.get("name") as! String
            let mail = document.get("mail") as! String
            let age = document.get("age") as! Int
            // Do something.
        }
    }
}

Recommended Posts

[Swift] Get document Id as well as document in Cloud Firestore
[Swift] Get key as well as value in Realtime database
[Swift] How to get the document ID of Firebase
Handle C char ** well in Swift
Output Notes document as XML document in Java
How to get the ID of a user authenticated with Firebase in Swift
Get contextual information such as HttpServletRequest in Jersey
Handle pointers such as UnsafePointer <T> in Swift
Get along with Java containers in Cloud Run