Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Firebase在Swift中检索自动ID下的数据_Ios_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

Ios Firebase在Swift中检索自动ID下的数据

Ios Firebase在Swift中检索自动ID下的数据,ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,我在从Firebase检索数据时遇到了麻烦 我想读取自动ID下JSON中的所有contactName数据,然后附加到UIPickerView 这是我的JSON树(使用childByAutoId()) 这是我的Swift密码 dbRef = Database.database().reference() dbRef.child("user").child("contacts").queryOrdered(byChild: "contactName").observeSingleEvent(of

我在从Firebase检索数据时遇到了麻烦

我想读取自动ID下JSON中的所有contactName数据,然后附加到UIPickerView

这是我的JSON树(使用childByAutoId())

这是我的Swift密码

dbRef = Database.database().reference()

dbRef.child("user").child("contacts").queryOrdered(byChild: "contactName").observeSingleEvent(of: .value, with: {(snapshot) in

    for snap in snapshot.children {

        let userSnap = snap as! DataSnapshot

        let contactName = userSnap.value as? String

            self.pickOption.append("\(contactName)")
        }
    })
但是结果显示所有的数据都是零。。。看起来像这样

我怎样才能修复它?

我自己解决了

但首先,我决定不使用UIPickerView

我想做的是在自动ID下面添加数据

我不确定这是解决这个问题的好算法,但无论如何,我做到了:)


尝试记录useSnap.value。你会知道问题出在哪里
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)
                        }
                    }
                })
            }
        }
    })