简体   繁体   中英

Cannot convert value of type '[String]?' to expected argument type 'String' Swift

I got lat long from API in string format now i want to change it to double.

let latitudeAll = [String]()

let double = 

NSNumberFormatter().numberFromString(latitudeAll)?.doubleValue

You need to access the particular array object with its index.

if latitudeAll.count > 0 {
    let double = NSNumberFormatter().numberFromString(latitudeAll[0])?.doubleValue
}

if you want Double Array from String array use this.

var doubleArr =  latitudeAll.map { Double($0) }

Here doubleArr is type of [Double?]

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