想从firebase获取数据

时间:2018-07-27 12:28:54

标签: ios swift firebase firebase-realtime-database

我可以获取所有数据,但是不知道如何进入节点内部 并获取值。这是我要获取所有数据的数据库结构

enter image description here

func fetchData(){
    ref = Database.database().reference()
    let userid = Auth.auth().currentUser?.uid

    ref.child(Constants.NODE_MAINTENANCE).child(userid!).child(Constants.NODE_MAINTENANCE_DATE).child(self.lastMaintenanceDateLbl.text ?? "").observe(DataEventType.value) { (snap) in



        guard snap.exists()
            else {
                print("no data found at this date")
                AppUtils.showAlert(title: "Alert", message: "No data found at this date!", viewController: self)
                return}

//             let maintenanceType = snapshot.value as? [String] ?? [""]
//            print(maintenanceType)

        if let snapshot = snap.children.allObjects as? [DataSnapshot]{

            for snap in snapshot{

                let maintenanceType = snap.value as? [String:Any]
                for type in (maintenanceType?.values)!{
                    print(type)


                }


            }
        }


    }

0 个答案:

没有答案