I came back to work on a project I have not touched in a week and suddenly my code was not working. I take a snapshot of data that I am sure exists (I can see it exactly in the database and changed no code) yet it is returning NSNULL for the snapshot and when I print snapshot.exists() I get false. I even tried printing snapshot.ref and typing that link into my browser and that takes me to the data on the console.
The only thing I did today was manually add a piece of data into my firebase console, but it was not in the same node where I am getting this error and it was working for a while after I made the change so I don't see how that could have caused this. Is anyone else having this issue or know why this would suddenly start happening?
Here is my code:
_ = ref.child("profiles").child((FIRAuth.auth()?.currentUser?.uid)!).child("type").observeSingleEventOfType(FIRDataEventType.Value, withBlock: { (snapshot) in
print(snapshot.exists())
print(snapshot.ref)
if (snapshot.value as! String == "Player") {
.....
}
})
I'm getting the error Could not cast value of type 'NSNull' (0x10d008600) to 'NSString' (0x10d3ffb48).' and as I said earlier snapshot.exists() is false and the ref link works.
Thanks!