0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

map(_:)メソッドによる配列の要素の型変換

Posted at

map(_:)メソッドを使った配列の要素の型変換

・Sequenceプロトコルが提供しているインターフェースのmap(_:)メソッドは、配列の全ての要素について特定の処理を用いて変換することができる。

例:String型の配列をInt型に型変換するとき

let stringNumArray = ["1","2","3"]

let intNumArray = stringNumArray.map{ Int($0) ?? 0 }

print(intNumArray) //[1,2,3]
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?