我想从Firebase获取数据

时间:2018-08-01 05:53:31

标签: ios swift firebase-realtime-database

this is the structher from where i want to fetch data

我试图在键中循环并获取值,这是我的代码,并卡在这里

func fetchData(){

    ref = Database.database().reference()
    let userid = Auth.auth().currentUser?.uid
    HUD.show(.progress)
    ref.child("start_shift").child(userid!).observeSingleEvent(of: .value) { (snapshot) in
        print(snapshot)
        let listOfShifts = snapshot.value as? [String:Any] ?? [:]
        for key in listOfShifts.keys{
            print(key)
            self.arrShiftKeys.append(key)
            self.ref.child(userid!).child(key).observeSingleEvent(of: .value, with: { (snap) in
                let dictionary = snap.value as? [String:Any] ?? [:]
                let assignmentType = dictionary["assignment_type"] as? String ?? ""
                print(assignmentType)
                let date = dictionary["date"] as? String ?? ""
                print(date)

            })

        }

    }
    HUD.hide()
    self.tableVieww.reloadData()
}

0 个答案:

没有答案