Well, Apple’s done it again, and made func parameters even simpler in Swift 3.0!
It’s all very straight forward now, class methods, static methods, global functions, init methods – they all work the same now, hooray!
1. Explicit parameter names
ALL parameter names by default are explicit:
class Person { init(firstName:String,surname:String) { (firstName,surname) } } var person = Person(firstName: "Tim", surname: "Cook")
2. External parameter name
The same parameter can have a different name externally and internally. This could be useful if different names make more sense depending on the perspective, or even for different human languages – perhaps the developer speaks a different language to the user of the class. The external parameter name comes first.
class Person { init(firstName 名字:String,surname 姓:String) { (名字,姓) } } var person = Person(firstName: "Tim", surname: "Cook")
3. implicit external parameter name
If for some reason you want your external parameter names to be implicit, you can use this external parameter name construct, and represent them with underscores:
class Person { init(_ firstName:String,_ surname:String) { (firstName,surname) } } var person = Person("Tim", "Cook")
For more on functions in Swift, check out my video:
[…] This post has been updated for Swift 3.0 here. […]
[…] Func parameters in Swift 3.0 […]
[…] ActionSwift3 uses a combination of the Swift and ActionScript approaches. You can read more about function parameters in Swift here. […]