从Cloud Firestore获取数据无

时间:2019-03-31 14:31:06

标签: ios swift google-cloud-firestore

当我按下getData按钮并开始运行代码时,docRef.getDcoument {(docSnapshot,错误)得到一个

线程1:致命错误:在展开可选值时意外发现nil

import UIKit
import Firebase

class MainPageViewController: UIViewController {

    var docRef: DocumentReference!

    @IBOutlet weak var userInfo: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()

        }
        // Do any additional setup after loading the view.


    @IBAction func getData(_ sender: Any) {
        docRef.getDocument { (docSnapshot, error) in
            guard let docSnapshot = docSnapshot, docSnapshot.exists else { return }
            let myData = docSnapshot.data()
            let campusID = myData?["campus_id"] as? String ?? ""
            let fName = myData?["f_name"] as? String ?? ""
           // let lName = myData?["l_name"] as? String ?? ""
          //  let points = myData?["points"] as? String ?? ""
            self.userInfo.text = "\"\(campusID)\" -- \(fName)"
        }
    }
}

0 个答案:

没有答案