 
 import FirebaseCore
 import FirebaseFirestore
+import FirebaseFirestoreSwift
 
 class ViewController: UIViewController {
 

        let docRef = db.collection("cities").document("BJ")

        docRef.getDocument { (document, error) in
            if let city = document.flatMap({
              $0.data().flatMap({ (data) in
                return City(dictionary: data)
              })
            }) {
                print("City: \(city)")
            } else {
                print("Document does not exist")
            }
        }
        // [END custom_type]

    }
}

public struct City: Decodable {

    let name: String
    let state: String?
    let country: String?
    let isCapital: Bool?
    let population: Int64?

    init(name: String, state: String?, country: String?, isCapital: Bool?, population: Int64?) {
        self.name = name
        self.state = state
        self.country = country
        self.isCapital = isCapital
        self.population = population
    }

    enum CodingKeys: String, CodingKey {
        case name
        case state
        case country
        case isCapital = "capital"
        case population
    }

}
