简体   繁体   中英

Swift Convert number to text

let winddir  = jsonResult["deg"]? as? Double
var val = ((winddir! / 22.5) + 0.5);
var arr = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];
return arr[(val % 16)]
println(arr)

Results in 'String' is not convertible to '()' with the line return arr[(val % 16)].
I am sure I am just missing one simple thing but I am stumped.

One certain problem and one likely—you need to use an Int for your array index:

return arr[Int(val % 16)]

The error message sounds to me like you didn't declare a return type for your function:

func getWindDirection() -> String {
    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM