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)
}
答案 0 :(得分:1)
那是因为您得到的不仅仅是一个用户,而是一个用户列表(如果您只有一个用户,则只有一个用户列表)。
做这样的循环:
for user in value.children.allObjects as! [DataSnapshot]
{
let status = user.childSnapshot(forPath: "status").value as? Int
print ("User status is : \(status)")
}