iDeveloper iDeveloper - 3 months ago 8
Swift Question

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

Answer

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?]