2016-09-25 94 views
0

我目前正在关注Udemy课程,该课程将教您如何使用Firebase创建聊天应用程序。然而,几周前我完成了这门课程,然后突然发布了Swift 3.0更新。我现在努力这条线转换成斯威夫特3火力地堡:Swift Firebase snapshot.allValues更新

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 { 

        } 
       } 
      } 

       //} 

      } 

     } 

    } 

但是,当然,这将返回一个错误。任何想法,我将如何解决这个特定的代码转换?

在此先感谢。

+0

提起错误的错误和线 – Dravidian

回答

3

尝试使用: -

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{ 

         } 
       } 
      } 
     } 

    }) 
+0

谢谢!有效! – askaale