Firebase with Swift ambiguous use of registerEventType function

I pull my hair out because of this. Turning to all the pages with related incidents and several tutorials, I find nothing wrong with my code here, but somehow it doesn't fail if I print out the values ​​(which work) or assign them like! NSArray, which then gives me an empty array.

print snapshot shows

( friend1, 
  friend2, 
  friend3 
)

I tried snapshot.value.values ​​... without dice. I tried to play with the unfolding ... without dice. and this is my last 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 again gives me ambiguity.

+4
source share
2 answers

Just some coding errors

: ( ) →

: , , snapshot.children -

, , - . self.friendsList.append(child.value)

let name = child.value["name"] as? String
friendsList.append(name!)

:

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)")
    }
})
+12
ref.observeSingleEvent(of: .value, with: { (snapshot) -> Void in

    })

, Xcode 8.3.2

0

All Articles