得到節點的值我讀了很多例子,他們大多有舊式(即使它們被寫入當年)。請幫忙瞭解我的代碼錯在哪裏?它是建立,但我不能讓一個價值123456
import UIKit
import Firebase
class ViewController: UIViewController {
@IBOutlet weak var val_txt: UITextField!
let ref = FIRDatabase.database().reference()
var barcode = 0
override func viewDidLoad() {
super.viewDidLoad()
FIRAuth.auth()?.signIn(withEmail: "*****@gmail.com", password: "*****", completion: {(user,error) in print("Авторизация Ок!!!")})
}
@IBAction func getData_btn(_ sender: Any) {
ref.child("goods").child("1").observe(FIRDataEventType.value, with: {(snapshot) in
let postDict = snapshot.value as? [String:AnyObject] ?? [:]
print(postDict["barcode"] as? Int)
})
print(barcode)
}
我已經改變的代碼,以便了解是否打印執行,我發現它不
print("Method started")
ref.child("goods").child("1").observe(FIRDataEventType.value, with:{(snapshot) in
let postDict = snapshot.value as? [String:AnyObject] ?? [:]
print("Method is executing")
})
print("Method completed")
我也得到打印
"Method started"
"Method completed"
後期圖像你的firebase結構 –
準備好鏈接我的結構 – LEONID
更新之後上面的評論它sa是我的「類ViewController沒有初始化器」,並在viewDidLoad成爲錯誤:「預期表達式」 – LEONID