LoginSignup
7
7

More than 5 years have passed since last update.

mapの記法が変わっている

Last updated at Posted at 2015-09-23

Swift 2.0 ,Xcode 7で、mapの記法が変わっているようである

古いやり方

let numbers = [4,7,2,9]
let array1 = map(numbers,{(let v:Int) -> Int in return v * 2})
print(array1)

これだとエラーが出るので、以下のように記するべきである

let numbers = [4,7,2,9]
let array1 = numbers.map({(let v:Int) -> Int in return v * 2})
print(array1)

ちなみに以下の記法もダメである

let numbers = [2,3,4,5]
let array2 = map(numbers){(let v:Int) -> Int in return v * 2}
print(array2)

以下のような記法が正しい

let numbers = [2,3,4,5]
let array2 = numbers.map(){(let v:Int) -> Int in return v * 2}
print(array2)

役立てていただければ幸いである。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7