Calling on Methods
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) ... |
Get Functional Programming: A PragPub Anthology now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.