简体   繁体   中英

Swift Firebase Snapshot query missing child

I store some settings in firebase database and reach this settings from app. It's working fine with the first 3 settings, but when I tried to add a new one, I can't reach this.

The code, what I use:

    func getLanguage(){
    ref = DatabaseRef.settingsRef
    //ref.observe(.value, with: { (snapshot) in
    ref.observeSingleEvent(of: .value, with: { (snapshot) in
        let valueL = snapshot.value as? NSDictionary
        if (valueL?.count)! > 0 {
            self.lang = ((valueL!["lang"])! as? String)!
        }
     })
}

DatabaseRef is a struct file to store all the references. settingsRef:

static let settingsRef = Database.database().reference().child("events").child(event).child("settings")

When I run this method, I got this error code on self.lang = ((valueL!["lang"])! as? String)!

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Ofcourse I double checked my database structure, and the path, but I can't figure out what is the problem, because my settings db looks like this:

     "settings" : {
         "contLog" : "true",
         "lang" : "en",
         "showStat" : "true",
         "useGate" : "true"
  },

And the snapshot looks like this:

快照

PS: I know "true" is not bool, it's just for string test.

Thanks for your answers, it was a cache problem. When I deleted the app from my phone (and from simulator), and rebuild it, everything works fine. Somehow the iOS stored older snapshots..

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