Firebase和完成处理程序

编程入门 行业动态 更新时间:2024-10-28 04:22:05
本文介绍了Firebase和完成处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在使用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和完成处理程序

本文发布于:2023-11-26 05:35:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632845.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!