The problem here is that there is an error message. In general, when you see something like cannot invoke .. with ...this, it means that the output of the compiler type just did not work.
. Swift , . :
arr.map() {
x in
return x + 2
}
: return x + 2. :
arr.map() {
x in
var y = x + 2
return y
}
(var y = x + 2), . , : , " map() ", : " , x y".
, , . return:
arr.map() {
x in
x + 2
}
:
arr.map() { $0 + 2 }
. , . (, , return , $0, x in - , ., , .)
: , , () :
arr.map { x in x + 2 }
@MartinR, :
let b: [Int] = arr.map { x in
var y = x + 2
return y
}
. (, " " , )