Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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 Swift Firebase snapshot.allValues更新_Ios_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

Ios Swift Firebase snapshot.allValues更新

Ios Swift Firebase snapshot.allValues更新,ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,我目前正在学习一门关于Udemy的课程,该课程教授如何使用Firebase创建聊天应用程序。然而,几周前我完成了这门课程,然后突然出现了Swift 3.0更新。我现在正在努力将这一行转换为Swift 3 Firebase: firebase.child("Recent").queryOrderedByChild("chatRoomID").queryEqualToValue(chatRoomID).observeSingleEventOfType(.Value) { (snapshot:FIRD

我目前正在学习一门关于Udemy的课程,该课程教授如何使用Firebase创建聊天应用程序。然而,几周前我完成了这门课程,然后突然出现了Swift 3.0更新。我现在正在努力将这一行转换为Swift 3 Firebase:

firebase.child("Recent").queryOrderedByChild("chatRoomID").queryEqualToValue(chatRoomID).observeSingleEventOfType(.Value) { (snapshot:FIRDataSnapshot) in


        var createRecent = true

        if snapshot.exists() {
            for recent in snapshot.value!.allValues {
                if recent["userId"] as! String == userId {
                    createRecent = false
                }
            }
        }

        if createRecent {

            CreateRecentItem(userId, chatRoomID: chatRoomID, members: members, withUserUsername: withUserUsername, withUserUserId: withUseruserId)


        }

    }
我试着这么做:

 firebase.child("Recent").queryOrdered(byChild: "chatRoomID").queryEqual(toValue: chatRoomID).observeSingleEvent(of: .value) { (snapshot:FIRDataSnapshot) in

        var createRecent = true

        if snapshot.exists() {

            if let values = snapshot.value as? [String:AnyObject] {

                for recent in values {
                    if recent["userId"] as! String == userId {

                    }
                }
            }

                //}

            }

        }

    }
但这当然返回了一个错误。关于如何解决这个特殊的代码转换问题,有什么想法吗

提前感谢。

尝试使用:-

firebase.child("Recent").queryOrdered(byChild: "chatRoomID").queryEqual(toValue: chatRoomID).observeSingleEvent(of: .value, with: { (snapshot:FIRDataSnapshot) in

        var createRecent = true

        if snapshot.exists() {

            if let values = snapshot.value as? [String:AnyObject] {

                for recent in values {
                    if let userId = recent.value["userId"] as? String{

                      }
                }
            }
        }

    })
尝试使用:-

firebase.child("Recent").queryOrdered(byChild: "chatRoomID").queryEqual(toValue: chatRoomID).observeSingleEvent(of: .value, with: { (snapshot:FIRDataSnapshot) in

        var createRecent = true

        if snapshot.exists() {

            if let values = snapshot.value as? [String:AnyObject] {

                for recent in values {
                    if let userId = recent.value["userId"] as? String{

                      }
                }
            }
        }

    })

说明错误和错误行说明错误和错误行