Ios Swift Firebase snapshot.allValues更新
我目前正在学习一门关于Udemy的课程,该课程教授如何使用Firebase创建聊天应用程序。然而,几周前我完成了这门课程,然后突然出现了Swift 3.0更新。我现在正在努力将这一行转换为Swift 3 Firebase: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
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{
}
}
}
}
})
说明错误和错误行说明错误和错误行