简体   繁体   English

从Firebase(iOS)读取数据

[英]Reading data from firebase (ios)

I have a small dataset in Firebase database, but unfortunately, I can't get read value from list correctly. 我在Firebase数据库中有一个小的数据集,但是不幸的是,我无法从列表中正确获取读取值。 Here is the structure of the database. 这是数据库的结构。 在此处输入图片说明

I just need to get the value of day and reference it to var. 我只需要获取day的值并将其引用给var。 Thanks in advance. 提前致谢。

var collnum = "" 
ref = Database.database().reference() 
let collid = ref.child("collid").child("day") 


collid.observeSingleEvent(of : .value, with : {(Snapshot) in

        print(Snapshot)

        if let snapDate = Snapshot.value as? String{
                    collnum = snapDate
                   print(snapDate)
            }
    })
   let database = FIRDatabase.database().reference()
   database.child("collid").queryOrderedByKey().observe(.value, with: 
   { 
       if let value = snapshot.value as? [String: AnyObject] 
       {
          let ui = value["day"] as! String
          print(ui)
       }  
   }

You can do something like this to read the data. 您可以执行类似的操作来读取数据。 This will read the data from the database and put into an array, allowing you to read the data. 这将从数据库中读取数据并将其放入数组中,从而使您可以读取数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM