Firebase retrieve data below auto ID In Swift

后端 未结 1 972
暖寄归人
暖寄归人 2021-01-20 20:27

I\'m in trouble in retrieving data from Firebase.

I\'d like to read all contactName data in JSON under auto ID , then append to UIPickerView.

Here is my JSO

相关标签:
1条回答
  • 2021-01-20 21:13

    I solved myself!

    But first of all, I decided not to use UIPickerView.

    And what I wanna do is to add data below auto ID.

    I'm not sure this is good algorithm for solving this problem, But Anyway, I made it :)

    dbRef.child("user/contacts/").observe(.value, with: {(snapshot) in
    
        if let result = snapshot.children.allObjects as? [DataSnapshot] {
    
                for child in result {
    
                    let orderID = child.key as String //get autoID
    
                    self.dbRef.child("user/contacts/\(orderID)/contactName").observe(.value, with: { (snapshot) in
    
                        if let nameDB = snapshot.value as? String {
    
                            if self.debtorName == nameDB {
    
                                self.dbRef.child("user/contacts/\(orderID)").updateChildValues(data)
                            }
                        }
                    })
                }
            }
        })
    
    0 讨论(0)
提交回复
热议问题