Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 具有func和返回数据的Firestore类_Ios_Swift_Class_Google Cloud Firestore - Fatal编程技术网

Ios 具有func和返回数据的Firestore类

Ios 具有func和返回数据的Firestore类,ios,swift,class,google-cloud-firestore,Ios,Swift,Class,Google Cloud Firestore,我如何创建一个类,用于从Firestore加载数据并在我的所有类中使用它 现在我有这门课,但他的结果是。。。未使用的: 我尝试在viewWillApear的其他类中使用这个类 但我得到了一个错误: 调用的结果。。。未使用 您需要使用补全 func loadBookingData(_ id: String, completion:@escaping(PhotoBooking?) -> ()) { firestore(FSCollections.p

我如何创建一个类,用于从Firestore加载数据并在我的所有类中使用它

现在我有这门课,但他的结果是。。。未使用的:

我尝试在viewWillApear的其他类中使用这个类

但我得到了一个错误:

调用的结果。。。未使用


您需要使用补全

func loadBookingData(_ id: String,
                 completion:@escaping(PhotoBooking?) -> ()) { 

    firestore(FSCollections.photoBooking).document(id).getDocument { (snapshot, error) in
        if let err = error {
            print(err.localizedDescription)
            completion(nil)
        } else {
            if let snap = snapshot, snap.exists {
                if let book = PhotoBooking(dictionary: snap.data()!, id: snap.documentID) {
                   completion(book)
                }
                else {
                   completion(nil)
                }
            }
            else {
                 completion(nil)
             }
        }
    } 
}
召唤


最好在viewDidLoad中加载数据。加载时间越早,并且调用oncePlease发布完整的错误消息。不要遗漏重要的细节。
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    FSLoadData.shared.loadBookingData(id, bookData: moreDetailBooking)
}
func loadBookingData(_ id: String,
                 completion:@escaping(PhotoBooking?) -> ()) { 

    firestore(FSCollections.photoBooking).document(id).getDocument { (snapshot, error) in
        if let err = error {
            print(err.localizedDescription)
            completion(nil)
        } else {
            if let snap = snapshot, snap.exists {
                if let book = PhotoBooking(dictionary: snap.data()!, id: snap.documentID) {
                   completion(book)
                }
                else {
                   completion(nil)
                }
            }
            else {
                 completion(nil)
             }
        }
    } 
}
loadBookingData("someValue") { data in 
    if let res = data {
      print(res)
    }
}