Method Parameter Names

Recall from Chapter 12 that the first parameter name is by default not used when calling a function or method. This convention impacts both how we name functions and how we name parameters.

To see this in action, open Zombie.swift and add a new method to change the name and limp status of an instance of the Zombie class.

Listing 15.16  changeName(_:walksWithLimp:) (Zombie.swift)

class Zombie: Monster {
    var walksWithLimp = true

    final override func terrorizeTown() {
        town?.changePopulation(-10)
        super.terrorizeTown()
    }

    func changeName(name: String, walksWithLimp: Bool) {
        self.name = name
        self.walksWithLimp = walksWithLimp
    }
}

changeName(_:walksWithLimp:) is a simple method that allows a developer to change ...

Get Swift Programming: The Big Nerd Ranch Guide 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.