我目前正在使用Firebase来检索用户信息.收到数据后,我想在所有闭包之外使用该数据,那么我将创建一个完成块,问题是我无法将完成变量添加到结果中,因为结果位于另一个闭包中.如何解决这个问题.预先感谢您的帮助.
Im currently using firebase to retrieve user info. once I receive the data I want to use the data outside of all closure the I create a completion block the problem is that I can not add the completion variable to the result because the result is inside another closure. How can fix this problem. Thank you in advance for the help.
func userInfo(userId:String,completion:(result:String)->Void){ fireBaseAPI().childRef("version_one/frontEnd/users/\(fireBaseAPI().currentUserId()!)/email").observeEventType(.Value, withBlock: {snapshot in let email = snapshot.value as! String //this is incorrect because it is inside a firebase closure how can I make it work I know i have it outside the closure but i will not be able to retrieve the info from firebase result = email }) } 推荐答案据我所知,您的问题:: ---
As far as i could understand your problem ::---
您希望在 completionBlock:中发送用户的emailID,但我仍然不知道 fireBaseAPI()是什么:-
You want to send the emailID of your user in the completionBlock: once retrieved, But i still don't have any idea to what fireBaseAPI() is :-
func userInfo(userId:String,completion:((result:String)->Void){ fireBaseAPI().childRef("version_one/frontEnd/users/\(fireBaseAPI().currentUserId()!)/email").observeEventType(.Value, withBlock: {snapshot in let email = snapshot.value as! String completion(result:email) }) }更多推荐
Firebase和完成处理程序
发布评论