swift - 我怎样才能得到 [String :Any] dictionary that I got from my firebase database? 中的状态值不是零

标签 swift firebase firebase-realtime-database nsdictionary

 self.ref.child("Users").queryOrdered(byChild: "phoneNumber").queryEqual(toValue: self.userMobile).observeSingleEvent(of: .value, with: { snapshot in

 if snapshot.value is NSNull{

    print("Not exists in database")
    self.performSegue(withIdentifier: "segue1", sender: self)
 }

 else{
     // Get user value
     let value = snapshot.value as! [String : Any]

     print(value)
     let status = value["status"] as? Int

     print ("User status is : \(status)")
     if status == 0 {

         self.performSegue(withIdentifier: "segue1", sender: self)
     }                 
     else if status == 1 {                       
         self.performSegue(withIdentifier: "segue2", sender: self)
     }

enter image description here

最佳答案

那是因为您得到的不仅仅是一个用户,而是一个用户列表(如果您只有一个用户,则得到一个包含一个用户的列表)。

所以做一个这样的循环:

for user in value.children.allObjects as! [DataSnapshot]
{
    let status = user.childSnapshot(forPath: "status").value as? Int
    print ("User status is : \(status)")
}

关于swift - 我怎样才能得到 [String :Any] dictionary that I got from my firebase database? 中的状态值不是零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51058082/

相关文章:

ios - 使用 Abid 打开 WhatsApp 对话不起作用

Angular Firestore 从 Doc 获取单个值

java - 如何将每个用户链接到 Firebase 中的数据?

swift - 从 Firebase 实时数据库获取数据返回 nil Swift

ios - SCNBox 在每张脸上都有不同的颜色或纹理

ios - 在 iOS 中等待 50 个运行循环周期

ios - 无法设置 NSUserDefaults

javascript - Firebase 在我的 Node.js 应用程序中的行为不正常

javascript - 使用云卵石 (Pebble.js) 访问 firebase

离线时的 Firebase setValue