I am really not quite understanding the updates to the Swift 3.0 Firebase syntax, but most of all retrieving values from children of a snapshot seems to be impossible. To do so, I use a snippet like this:
if let snapVal = snapshot.value as? [String: AnyObject] {
for c in snapshot.children {
let cx = (c as! AnyObject)
let name = cx["NAME"] as! String
}
}
I have taken many approaches to this but FIRDatabaseSnapshot has many restrictions in the new Swift 3 update, and AnyObject does not allow for values to be read from the object and NSDictionary-like types do not have children either. All help is very appreciated, thank you!
The snapShot that you receive of type
FIRDataSnapshot
is actually a custom class conforming toNSObject
, so only the variables conforming toFIRDataSnapshot
can access the custom function thatFIRDataSnapshot
provides such as.children
.But when you are accessing a new variable whose value is
snap.value
parsed as [String:AnyObject], basically it becomes a NSDictionary, and NSDictionary doesn't has any parameter.children
.