July 2017
Intermediate to advanced
284 pages
6h 45m
English
When encapsulated in a class (or struct or enum), the first parameter name of a method is not included externally, while all following parameter names are included externally when the method is called:
| | class MyFunClass { |
| | |
| | func hello(name: String, age: Int, location: String) { |
| | println("Hello \(name). I live in \(location) too. |
| | When is your \(age + 1)th birthday?") |
| | } |
| | |
| | } |
| | |
| | let myFunClass = MyFunClass() |
| | myFunClass.hello("Mr. Roboto", age: 5, location: "San Francisco") |
It is therefore best practice to include your first parameter name in your method name, just like in Objective-C:
| | class MyFunClass { |
| | |
| | func helloWithName(name: String, age: Int, location: String) { |
| | println("Hello \(name). I live in \(location) ... |
Read now
Unlock full access