I've been pulling my hair out because of this. Going to all the pages with related incidents and multiple tutorials I find nothing wrong with my code here, but somehow it only doesn't fail if I print out the values (which works) or assign them as! NSArray which then gives me an empty array.
a print of snapshot.value shows
( friend1, 
  friend2, 
  friend3 
)
I've tried snapshot.value.values ... no dice. I've tried playing with the unwrapping ... no dice. and this is my final attempt:
    friendsList = [String]()
    ref.observeSingleEventOfType(.Value) { (snapshot) -> Void in
        if snapshot.value is NSNull {
        } else {
            for child in snapshot {
                self.friendsList.append(child.value)
            }
        }
    }
which gives me the ambiguous thing again.
Just some coding errors
Remove: (snapshot)-> Void
Change: child in snapshot as snapshot is not a sequence, whereas snapshot.children is
I assume you want to store the friends name as a string and name is a key in your structure. So change self.friendsList.append(child.value) to
let name = child.value["name"] as? String
friendsList.append(name!)
Here's the corrected code:
var friendsList = [String]()
ref.observeSingleEventOfType(.Value, withBlock: { snapshot in
    if snapshot.value is NSNull {
    } else {
        for child in snapshot.children {
            let name = child.value["name"] as? String
            friendsList.append(name!)
        }
        print("\(friendsList)")
    }
})
                        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