O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required