xcode - Cast JSON AnyObject to Double (Swift) -


i want cast anyobject json double in swift.

let value = double(jsonresult["counter"]) not work

let value = jsonresult["counter"] as? double not work

let value = jsonresult["counter"] as! double not work

numbers in dictionaries(/from json) nsnumber. can use (jsonresult["counter"] as? nsnumber).doublevalue. (the double type not class, can't anyobject.)


edit: sounds server returning data as string, {"counter": "1234"}.

in case, can take advantage of nsstring method called doublevalue parses string (or can use integervalue):

if let counter = (parsejson["counter"] as? nsstring)?.doublevalue {     // } 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -