约会后的孩子如何从Firebase读取?

时间:2018-07-24 06:50:18

标签: swift firebase firebase-realtime-database

我这样上传到Firebase:

 //Get date and time
        let date = Date()
        let calendar = Calendar.current
        let hour = calendar.component(.hour, from: date)
        let minute = calendar.component(.minute, from: date)
        let second = calendar.component(.second, from: date)
        let year = calendar.component(.year, from: date)
        let month = calendar.component(.month, from: date)
        let day = calendar.component(.day, from: date)
        let dateAndTime = ("\(day)-\(month)-\(year) at: \(hour):\(minute):\(second)")    

 let userData = ["CreatedOn" : timeStamp, "Order" : dataArray] as [String : Any]
        self.ref?.child("users").child(user).child("Orders").child(dateAndTime).updateChildValues(userData, withCompletionBlock: { (error, ref) in
            if error != nil{
                print(error!)
                return
            }
        })

我如何阅读.child(dateAndTime)之后的内容?每次用户上传时,此子项都会有所区别。

1 个答案:

答案 0 :(得分:0)

我认为您可以使用“ DataSnapshot”。每次读取数据库数据时,您都会以DataSnapshot的形式接收数据。