I got this error, but I'm trying to get a String
from a Dictionary
. This is my code:
FIRDatabase.database().reference().child("users").child(uid).observeEventType(.ChildAdded, withBlock: { (snapshot) in
let dictionary = snapshot.value as! NSDictionary
if let username = dictionary["name"] as? String {
cell.name.text = username
}
if let userlogin = dictionary["login"] as? String {
cell.login.text = userlogin
}
})
In my Firebase Database "name" and "login" are both Strings. I cannot understand what's the problem.
Any help would be greatly appreciated!
Issue regards snapshot cast to NSDictionary. Since snapshot value is a String. Try this:
FIRDatabase.database().reference().child("users").child(uid).observeEventType(.ChildAdded, withBlock: { (snapshot) in
if let dictionary = snapshot.value as? NSDictionary {
if let username = dictionary["name"] as? String {
cell.name.text = username
}
if let userlogin = dictionary["login"] as? String {
cell.login.text = userlogin
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With