title: Swift Firebase Custom Object with Document ID
body: <p>Is there a way to create a custom Swift Object where I assign the Firebase Document ID to a Object parameter? </p>
  
  <p>Code taken from here: <a href="https://firebase.google.com/docs/firestore/query-data/get-data#custom_objects" rel="nofollow noreferrer">https://firebase.google.com/docs/firestore/query-data/get-data#custom_objects</a></p>
  
  <pre><code>public struct City: Codable {
      let id: String // here I'd like to fill in the Document ID
      let name: String?
      let state: String?
      let country: String?
      let isCapital: Bool?
      let population: Int64?
  
      enum CodingKeys: String, CodingKey {
          case id = //Document ID
          case name
          case state
          case country
          case isCapital
          case population
      }
  }
  </code></pre>
  
  <p>Getting Firebase document and creating the Object. Code also taken from Goolge Firebase link above.</p>
  
  <pre><code>fun getObject(){
  
  let db = Firestore.firestore()
  let docRef = db.collection("cities").document("BJ")
  
  docRef.getDocument { (document, error) in
      if let error = error {
          print("Error retrieving document: \(error)")
          return
      }
      let result = Result {
        try document?.data(as: City.self)
      }
      switch result {
      case .success(let city):
          if let city = city {
              // A `City` value was successfully initialized from the DocumentSnapshot.
              print("City: \(city)")
          } else {
              // A nil value was successfully initialized from the DocumentSnapshot,
              // or the DocumentSnapshot was nil.
              print("Document does not exist")
          }
      case .failure(let error):
          // A `City` value could not be initialized from the DocumentSnapshot.
          print("Error decoding city: \(error)")
      }
  }
  }```
  </code></pre>