如何从Firebase快照设置变量(Swift) [英] How to set variables from a Firebase snapshot (swift)

查看:81
本文介绍了如何从Firebase快照设置变量(Swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Firebase快照中获取数据并将其设置为Project中的变量.我得到了数据,但是我不知道如何解析它,所以我可以对其进行设置.我正在尝试做类似SwiftyJSON对API调用的操作.

I would like to grab the data from my Firebase snapshot and set it to variables in my Project. I get the data, but I don't know how to parse it so I can set them. I'm trying to do something like what SwiftyJSON does with API calls.

是否有任何方法可以解析和设置(ls)数组中的值,并将每个节点的"fromId","text","toId"设置为不同的变量?

Is there any way to parse and set values from the (ls) array and set the "fromId", "text", "toId" to different variables for each node?

推荐答案

尝试使用:-

FIRDatabase.database().reference().child("users/userID/ls").observeSingleEvent(of : .value, with : {(Snap) in 

  if let snapDict = Snap.value as? [String:AnyObject]{

      for each in snapDict{

           print("\(each.value["fromId"] as! String)")

         }
   }
})

这篇关于如何从Firebase快照设置变量(Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆