関数内で使用する引数名以外に、関数の呼び出し元で引数の意味を分かりやすくするために外部引数名をつけることができる。
関数内の引数名と外部引数名が同じ場合は”#”を関数内引数名の前につけることで省略することができる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//外部引数名を定義 | |
func convertSeconds(hour h:Int , minutes m:Int) -> Int{ | |
return 60 * (60 * h + m ) | |
} | |
//外部引数名と引数名が同じ場合 | |
func convertSeconds2(#hour:Int , #minutes:Int) -> Int{ | |
return 60 * (60 * hour + minutes ) | |
} | |
// | |
convertSeconds(hour: 3, minutes: 25) //12,300 | |
convertSeconds2(hour: 3, minutes: 25) //12,300 |