ios - NSMutableDictionary treats NSString value as NSNumber -


i have following value in nsmutabledictionary - see image

enter image description here

i'm attempting @ "a" thus:

let = dictionary.objectforkey("a") as! string 

the app crashes @ point with

could not cast value of type '__nscfnumber' (0x...) 'nsstring' (0x...).

other numbers inside "" treated strings numbers outside of strings cast string without issue.

can let me know what's going on? , how @ these values easily?

the value nsnumber, not nsstring. can use stringvalue convert it:

if let = d["a"] as? nsnumber {     let astring = a.stringvalue     println(astring) // -1 } else {     // either d doesn't have value key "a", or d value not nsnumber } 

if you're sure exists , nsnumber, can use forced unwrapping, forced casting, , string interpolation:

let = d["a"]! as! nsnumber let astring = "\(a)" 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -