【发布时间】:2016-10-25 04:19:40
【问题描述】:
不退出观察块。
不打印 hello 或 events。
卡在从数据库中获取。
显示来自 Firebase 但不在块外的数据。
例如:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let databaseRef = FIRDatabase.database().reference()
databaseRef.child("Events").queryOrderedByKey().observe(.childAdded, with: {
snapshot in
print(snapshot)
var temp : event = event()
temp.name = (snapshot.value as? NSDictionary)?["name"] as? String ?? ""
temp.description = (snapshot.value as? NSDictionary)?["description"] as? String ?? ""
temp.date = (snapshot.value as? NSDictionary)?["date"] as? String ?? ""
temp.price = (snapshot.value as? NSDictionary)?["price"] as? String ?? ""
temp.venue = (snapshot.value as? NSDictionary)?["venue"] as? String ?? ""
temp.genre1 = (snapshot.value as? NSDictionary)?["genre1"] as? String ?? ""
temp.genre2 = (snapshot.value as? NSDictionary)?["genre2"] as? String ?? ""
temp.img = (snapshot.value as? NSDictionary)?["img"] as? String ?? ""
self.events.append(temp)
print(self.events)
})
print("Hello")
print(self.events)
}
提前致谢!
【问题讨论】:
标签: ios swift firebase firebase-realtime-database swift3