astrocat1997 astrocat1997 - 2 years ago 659
Swift Question

how do you get children count from Firebase in swift?

I'm trying to find out how many children my key has but when I try using

var count = 0

ref.observeEventType(.Value, withBlock: { snapshot in

count += snapshot.childrenCount

It gives me an error. How should I be doing this?

Answer Source

That's weird... what you posted works for me... maybe the DataObject is not what is expected... Test this by adding a breakpoint and seeing what snapshot is.

You can try this instead... it should yield same result as the one that doesn't work for you, so maybe it won't work either:


EDIT: Ah, I think I know why you're not able to get the children count property! Try casting snapshot to FDataSnapShot! So try

ref.observeEventType(.Value, withBlock: { (snapshot: FDataSnapshot!) in
        count += snapshot.childrenCount
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download