7
6

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 5 years have passed since last update.

クロージャを調べてみた

Posted at

クロージャを使えば関数の処理を省略的に書ける#

変数に内容を代入することができ、その場合は{}でくくればできます。
関数名は書きません。


import Foundation

 var Closure = { (num1 : Int , num2 : Int) -> Int in
    return num1 * num2
}

print(Closure(10, 10))  //100

関数の宣言、インスタンスを生成といった記述を簡潔に書けます。
swiftでは関数を値として処理する。

短くて済むし解りやすい!

7
6
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
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?