Convert JSON Array to Int Array In Swift -
this may silly question, despite digging through questions here on stackoverflow, can't seem find use case matches predicament.
namely, have data being pulled rest service spits out historical data json;
[ { "city": "new york", "historicaltemps": "98.46,71.81,76.58,82.38,91.08", "timestamp": "2015-06-04 10:20:34", } ]
i able parse data in ios app, , setting historicaltemps string. i'm failing, however, figuring out how convert comma-separated string int array can populate graph. i've stalled;
var arr = historicaltemps.componentsseparatedbystring(",") println(arr) //prints [98.46,71.81,76.58,82.38,91.08] want.
my attempts figure out how convert string array int array, however, failing me. possible suggestions?
thank you!
try following:
let str = "98.46,71.81,76.58,82.38,91.08" let arr = split(str) { $0 == "," } let nums = map(arr) { ($0 nsstring).doublevalue } println(nums) // [98.46, 71.81, 76.58, 82.38, 91.08]
Comments
Post a Comment