firebase - Swift - Could not cast value of type '__NSCFString' to 'NSDictionary' -


i got error, i'm trying string dictionary. code:

firdatabase.database().reference().child("users").child(uid).observeeventtype(.childadded, withblock: { (snapshot) in              let dictionary = snapshot.value as! nsdictionary              if let username = dictionary["name"] as? string {                 cell.name.text = username             }              if let userlogin = dictionary["login"] as? string {                 cell.login.text = userlogin             }          }) 

in firebase database "name" , "login" both strings. cannot understand what's problem.

any appreciated!

issue regards snapshot cast nsdictionary. since snapshot value string. try this:

firdatabase.database().reference().child("users").child(uid).observeeventtype(.childadded, withblock: { (snapshot) in          if let dictionary = snapshot.value as? nsdictionary {              if let username = dictionary["name"] as? string {                 cell.name.text = username             }              if let userlogin = dictionary["login"] as? string {                 cell.login.text = userlogin             }         }     }) 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -