用firebase完成处理程序不起作用
我尝试从Firebase获取值,然后我想打印执行第二行的代码,然后是TRUE。
但是订单是完全错误的。我在做什么错?
override func viewDidLoad() {
super.viewDidLoad()
method(arg: true, completion: { (success) -> Void in
print("Second line of code executed")
if success { // this will be equal to whatever value is set in this method call
print("true")
} else {
print("false")
}
})
}
func method(arg: Bool, completion: (Bool) -> ()) {
let userID = Auth.auth().currentUser!.uid
let database = Database.database().reference()
database.child("user/\(userID)/abonniertePoi/").observe(.value, with: { snapshot in
for child in snapshot.children.allObjects as! [DataSnapshot] {
myFeed.myArray1.append(child.key)
}
print(myFeed.myArray1)
})
completion(arg)
}
它首先打印第二行执行,然后执行firebase请求,然后说为true。
I try to get the values from Firebase and after that I want to print the second line of code executed and then true.
But the order is total wrong. What am I doing wrong?
override func viewDidLoad() {
super.viewDidLoad()
method(arg: true, completion: { (success) -> Void in
print("Second line of code executed")
if success { // this will be equal to whatever value is set in this method call
print("true")
} else {
print("false")
}
})
}
func method(arg: Bool, completion: (Bool) -> ()) {
let userID = Auth.auth().currentUser!.uid
let database = Database.database().reference()
database.child("user/\(userID)/abonniertePoi/").observe(.value, with: { snapshot in
for child in snapshot.children.allObjects as! [DataSnapshot] {
myFeed.myArray1.append(child.key)
}
print(myFeed.myArray1)
})
completion(arg)
}
It first prints second line executed then does the Firebase request and then says true.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论