JamesG JamesG - 1 year ago 111
Swift Question

Read from firebase database with Swift

I'm struggling to get the value I need from Firebase

I have this setup

- version : 1.0

and I am trying to get it like so:

let refHandle = dbRootRef.observe(FIRDataEventType.value, with: { (snapshot) in
let postDict = snapshot.value as? [String : AnyObject] ?? [:]

Can someone help me get the 1.0 from the database?

p.s - no errors and nothing in the console

Jay Jay
Answer Source

try this

let ref = "path to your Firebase/version" //point directly to the version node

ref.observe(FIRDataEventType.value, with: { (snapshot) in
        print(snapshot?.value) //prints 1

Testing rules: set to

  "rules": {
    ".read": true,
    ".write": true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download