JamesG JamesG - 1 month ago 17
Swift Question

Read from firebase database with Swift

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

I have this setup

MyAppName:
- 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] ?? [:]
print(postDict)
})


Can someone help me get the 1.0 from the database?

p.s - no errors and nothing in the console

Jay Jay
Answer

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
  }
}