왜 argument label을 앞에 붙여야 하는가?
Swift error: missing argument label 'name:' in call
Swift requires argument labels by default, because it supports classes with multiple initializers. The benefit of argument labels comes from the ability of Swift to infer which initializer to use; not only by argument type, but argument name as well.struct Celsius { var temperatureInCelsius: Double = 0.0 init(fromFahrenheit fahrenheit: Double) { temperatureInCelsius = (fahrenheit - 32.0) / 1.8 } init(fromKelvin kelvin: Double) { temperatureInCelsius = kelvin - 273.15 } } let boilingPointOfWater = Celsius(fromFahrenheit: 212.0) // boilingPointOfWater.temperatureInCelsius is 100.0 let freezingPointOfWater = Celsius(fromKelvin: 273.15) // freezingPointOfWater.temperatureInCelsius is 0.0
See this page for more details: https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_272
'iOS > swift' 카테고리의 다른 글
GCD(Grand Central Patch) (0) | 2020.07.18 |
---|---|
URLSession (0) | 2020.07.04 |
[swift] ViewController간 이동 (0) | 2020.05.01 |
네트워크 (0) | 2020.04.30 |
xcode에서 iPhone연결하기 (0) | 2020.04.26 |