得到节点的值我读了很多例子,他们大多有旧式(即使它们被写入当年)。请帮忙了解我的代码错在哪里?它是建立,但我不能让一个价值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