简体   繁体   中英

Issue retrieving data from Firebase Swift 3.0

For some reason I can't retrieve data from Firebase. Basically the code "skips" the ref-section and moves on, and I have no clue why it does this. I have tried to look at documentation as well as other questions on StackExchange and I can't figure out the problem. please help. thanks!

func getMeta() {

    ref.child("Meta").child("Topics").observeSingleEvent(of: .value, with: { (snapshot) in

        let value = snapshot.value as? NSDictionary

        if let actualValue = value {

            print(actualValue)

        }
    })
}

I actually want to do more things with actualValue but I can't even get the code to print it. The Firebase json looks like this:

{
  "Meta" : {
    "Levels" : {
      "LevelOne" : [ "q0001", "q0002" ],
      "LevelTwo" : [ "q0003" ]
    },
    "Topics" : {
      "France" : { 
           0: "q0001", 
           1: "q0002" },
      "UK" : {
           0: "q0003" }
    }
  }
}

When I try to

print(snapshot) 

after the code skips the section, I get this error

error: <EXPR>:3:1: error: use of unresolved identifier 'snapshot'
snapshot ^~~~~~~~

If you're signed in using Firebase Auth, log out and try again.

I deleted the user manually in Firebase console but in my app I was still signed in with the user. I logged out and the code does not skip the ref section anymore.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM