For the More Curious: Initializer Parameters

Like functions and methods, initializers can provide explicit external parameter names. External parameter names distinguish between the parameter names available to callers and the local parameter names used in the initializer’s implementation. Because initializers follow different naming conventions than functions (i.e., initializer names are always init), the parameters’ names and types help to determine which initializer should be called. Thus, Swift provides external parameter names for all of the initializer’s arguments by default.

You can provide your own external parameter names as needed. For example, imagine a WeightRecordInLBS struct that should be able to be initialized with ...

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.