我一直在使用 firebase 从 firebase 数据库检索测试数据并将值设置为标签,但我遇到的问题是我想将数据检索为 Int 而不是 String。
func retData(){
rootRef.child("users").child("Test").observeEventType(.Value){
(snap: FIRDataSnapshot) in
self.simpleLabel.text = snap.value?.description
} }
最佳答案
Firebase 将数据表示为 JSON 字符串,并且只能这样检索。我在最近的一个项目中遇到了类似的问题,不得不求助于 int>string 将数据推送到 FB,并求助于 string>int 从 FB 检索到的字符串。没有为这个问题提交代码,但基本上你必须转换 int使用构造函数语法作为字符串:
让 myStr = String(myInt) //将字符串推送到 Firebase
……
//从 Firebase 中拉回字符串
让 myInt =Int(myStr)
关于swift - Firebase:从实时数据库中检索数据作为 Int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38851936/