Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
711 views
in Technique[技术] by (71.8m points)

swift - Read Data Firebase assign value

I want to assign the data I have read in the Firebase database to the values I have given in the code. The data is being read in the code I have given, but the values are not being assigned. I want to assign deviceroom1, deviceRoom2, deviceRoom3, deviceRoom4.

    var deviceRoom1: String = ""
    var deviceRoom2: String = ""
    var deviceRoom3: String = ""
    var deviceRoom4: String = ""
    var deviceRoom5: String = ""

 func fetchDevies(){

        let ref = Database.database().reference().child(self.chip1InfoString!).child("Rooms")

        ref.observeSingleEvent(of: .value, with: { (snapshot) in
            let value = snapshot.value as? NSDictionary

            if let deviceRooms1 = value?["Rooms1"] as? String  {
                self.deviceRoom1 = deviceRooms1

            }
            if let deviceRooms2 = value?["Rooms2"] as? String {
                self.deviceRoom2 = deviceRooms2

            }
            if let deviceRooms3 = value?["Rooms3"] as? String {
                self.deviceRoom3 = deviceRooms3

            }
            if let deviceRooms4 = value?["Rooms4"] as? String {
                self.deviceRoom4 = deviceRooms4

            }
            if let deviceRooms5 = value?["Rooms5"] as? String {
                self.deviceRoom5 = deviceRooms5

            }
        }) { (error) in
            print(error.localizedDescription)
        }

                let items = [deviceRoom1, deviceRoom2, deviceRoom3, deviceRoom4, deviceRoom5]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...