[Xcode 7.1, iOS 9.1]
I have an array: var array: [String] = [\"11\", \"43\", \"26\", \"11\", \"45\", \"40\"]
var array: [String] = [\"11\", \"43\", \"26\", \"11\", \"45\", \"40\"]
I want to convert that (each index
Swift 4, 5:
Use compactMap with cast to Int, solution without '!'.
let array = ["1","foo","0","bar","100"] let arrayInt = array.compactMap { Int($0) } print(arrayInt) // [1, 0, 100]