Having some trouble understanding firebase with Swift 3.
I redid my observer like this:
currentUserFirebaseReference.observeSingleEvent(of: .value, with: { (snapshot: FIRDataSnapshot) in let UID = snapshot.key let dict = snapshot.value as! Dictionary<String,AnyObject> let pictureURL = dict["pictureURL"] as! String
I just did
observation..... in { let picture = snapshot.value!["pictureURL"]
But now, I think, you need to explicitly tell Firebase that you are dealing with a Dictionary?
My problem occurs when I try to set a value.
I add pictureURL on top to the Person class, and later I do:
let picURL = self.currentUserInfo.pictureURL // The picture from before let info = ["pictureURL" : picURL, ....morestuff] as [String : Any] // Swift conversion added the String:Any bit. Assume this is correct? ref.setValue(info)
and I get this error:
Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(setValue:) Cannot store object of type _SwiftValue at pictureURL. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.
Why is this happening and how can I fix it?
edit:
So, I found out that this only happens when trying to extract information from the class.
let data : Dictionary<String, Any> = ["Cats" : 3, "Dogs" : 9] DataService.ds.REF_BASE.child("testing").setValue(data)
The above code works.
class Dog { var fur : String? } let dog = Dog() dog.fur = "Brown" let data : Dictionary<String, Any> = ["Cats" : 3, "Dogs" : 9, "DogFur" : dog.fur] DataService.ds.REF_BASE.child("testing").setValue(data)
This code crashes and says that I cannot assign a swiftvalue type.