ios - Firebase how to get NSDictionary data -
i data in user profile, i've got info got stuck @ one.
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
Post a Comment