I'm reading "The swift programming language 4.2". In the beginning chapter, page 23, I have this following requirement:
Rewrite the closure to return zero for all odd number
And my solution is:
let myArray: [Int] = [1, 2, 3, 4, 5]
myArray.map({ (number: Int) in
if number % 2 != 0 {
return 0
} else {
return number
}
})
But I have this following error:
Ambiguous reference to member 'map'
I really do not understand why I'm wrong, why my 'myArray' can not references to 'map' member? Could you give me and explanation of this error and the right solution for this? Thank you!