I’m following the instructions from https://firebase.google.com/docs/database/ios/read-and-write to read a record from Firebase Realtime Database:
StorageWrapper.ref.child("users").child(id)
.observeSingleEvent(of: .value, with:
{
snapshot in
print("DEBUG: snapshot value = (String(describing: snapshot.value))")
if let value = snapshot.value as? NSDictionary
{
print("DEBUG: value = (String(describing: value))")
if let email = value["email"] as? String,
let fullname = value["fullname"] as? String
{
user = User(id: id, fullname: fullname, email: email)
print("DEBUG: snapshotted user (String(describing: user))")
}
}
The snapshot is valid and the first print statement returns:
DEBUG: snapshot value = Optional(["email": [email protected],"fullname": Joe Tester])
The conversion to NSDictionary fails. I’ve also tried converting the snapshot value to [String: Any]
and [String: String]
with no luck.
Am I missing something simple?