ios - NSMutableDictionary treats NSString value as NSNumber -
i have following value in nsmutabledictionary - see image
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
Post a Comment