so i have this simple code and have problem with swift data type, want to map this array from
["a", "b", nil, "c", "d", nil]
to
["a", "b", "z", "c", "d", "z"]
so, this is my current code
import Foundation
let array1 = ["a", "b", nil, "c", "d", nil]
let newArray = array1.map { (currentIndex: Any) -> String in
if currentIndex == nil {
return "z"
}
return currentIndex as! String
}
print(newArray)
I am grateful if you try to solve the code. thank you.