LoginSignup
2
2

More than 5 years have passed since last update.

メソッドに任意で外部引数名を設定できる

Posted at

なんとなくSwiftを使っていたら、メソッドの引数でラベルを使うやつが出てきた。

presentViewController(myAlert, animated: true, completion: nil)

とか。
これはメソッドの定義時にラベルを設定している。

func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?)

func(ラベル 引数名:型)という指定ができる。
func(ラベル 引数名:型)が、呼び出し時にfunc(ラベル:変数名)という形になるので知らないと混乱する。


こちらの説明がわかりやすい。
Swiftにおける名前付き引数


公式本の「The Swift Programming Language」だと、239ページ目の「External Parameter Names」
こちらの説明もまたわかりやすい。

Apple本

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