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

    }
}

fileprivate struct City {

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

    init?(dictionary: [String: Any]) {
        guard let name = dictionary["name"] as? String else { return nil }
        self.name = name

        self.state = dictionary["state"] as? String
        self.country = dictionary["country"] as? String
        self.capital = dictionary["capital"] as? Bool
        self.population = dictionary["population"] as? Int64
    }

}


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

        docRef.getDocument { (document, error) in
            let result = Result {
                try document.flatMap {
                    try $0.data(as: City.self)
                }
            }
            switch result {
            case .success(let city):
                if let city = city {
                    print("City: \(city)")
                } else {
                    print("Document does not exist")
                }
            case .failure(let error):
                print("Error decoding city: \(error)")
            }
        }
        // [END custom_type]
