ios - Firebase how to get NSDictionary data -


i data in user profile, i've got info got stuck @ one.

firebase database: enter image description here

here of code:

self.ref.child("users").child("profile").observe(.childadded, with: { (snapshot) in           if let dictionary = snapshot.value as? [string:any] {              let user = user()              let brands = dictionary["status"] as! nsdictionary               user.displayname = dictionary["displayname"] as? string             user.isconnected = brands["isconnected"] as? string              print(user.isconnected) //fatal error: unexpectedly found nil while unwrapping optional value   class user: nsobject {     var displayname: string?     var isconnected: string? } 

try :

guard let dictionary = snapshot.value as? [string: any] else {     return }  guard let statusdictionary = dictionary["status"] as? [string: any] else {     return }  guard let devicestatusdictionary = statusdictionary["device_key"] as? [string: any] else {     return }  let user = user()  user.displayname = dictionary["displayname"] as? string user.isconnected = devicestatusdictionary["isconnected"] as? bool 

you need know device key.

and :

class user: nsobject {     var displayname: string?     var isconnected: bool? } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -