Errata

Head First Swift

Errata for Head First Swift

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Chapter 4. `Functions and Enums: Reusing Code on Demand`, in section `Functions deal in values`

In Chapter 4. `Functions and Enums: Reusing Code on Demand`

In Section `Functions deal in values`:

The function definition of `multiplyBy42` does not compile.

func multiplyBy42(_ number: Int) {
number = number * 42
print("The number multiplied by 42 is: \(number)")
}

Error message: Cannot assign to value: 'number' is a 'let' constant.

Note from the Author or Editor:
The function multiplyBy42 should read:


func multiplyBy42(_ number: Int) {

let result = number * 42

print("The number multiplied by 42 is: \(result)")

}

The version in the book attempts to assign the result of multiplying number * 42 back to number, but because of the way functions work number is a constant and cannot be modified.

This revised version creates a constant named result inside the function and uses that, and then prints it.

Anonymous  Jan 12, 2022