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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

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

Version Location Description Submitted by Date submitted
Chapter 6 - Changing properties using methods

With respect to mutating functions , by way of a NOTE it has been mentioned that:

NOTE
A mutating method cannot call a non-mutating method. It can all other mutating methods, though..

However , SI could not find reference of this concept and and I tried the same in playground I can call the non mutating function from a mutating function.


struct TestStruct {

var a = 2

mutating func testMutate(b : Int){
a = b
nonMutating()
}

func nonMutating(){

print("non mutating func called")
}
}

var myStruct = TestStruct()
myStruct.testMutate(b: 2)

pankaj  Oct 06, 2021 
Chapter 4. `Functions and Enums: Reusing Code on Demand`, in section `Function types work like every other type`

In chapter 4. `Functions and Enums: Reusing Code on Demand`.
In section `Function types work like every other type`

Both `print` functions miss the backslash symbol (`\`) for string interpolation.
And `manipulateInteger` will be printed as a string, instead of being called as a function.

print("The result is: (manipulateInteger(10, 90))")
should be:
print("The result is: \(manipulateInteger(10, 90))")

print("The result is: (manipulateInteger(2, 5))")
should be:
print("The result is: \(manipulateInteger(2, 5))")

Anonymous  Jan 13, 2022 
Printed Page Page 130
Center

I am unable to locate where, in Chapter 4, the answers for the following are found:

5 down — Continue
12 down - Defer
13 across - Defer

The solution, as defined on page 132, seems impossible to achieve soley on the contents of Chapter 4.

Anonymous  Aug 10, 2022 
Chapter 11 brain power section
Brain power, I don't have a page number.

You ask folks to draw a triangle, unless I am missing something, there is no triangle shape, perhaps you meant rectangle?

Anonymous  Dec 23, 2022 
ePub Page chapter 10, your first SwiftUI UI
HuzzahView

The sample code won't compile. Last line needs to be

PlaygroundPage.current.setLiveView(HuzzahView())

HuzzahView, instead of ContentView

Johannes  Dec 24, 2022 
ePub Page chapter 10, DrinkCounterView example
right after DrinkCounterView example

After having presented the - not yet working - DrinkCounterView code, you talk about BirdCounterView twice in the text that immediately follows.

Johannes  Dec 24, 2022 
Printed Page 23
Exercise

The exercise asks the user to modify the ingredients array by appending a value; however, the array was defined as a constant, so this will fail unless the user changes the array to a variable. This should be made more clear.

James Leno  Jun 18, 2022 
Printed Page 23
"Exercise" section

The Exercise section describes the process to append a new element to the "ingredients" array, using the .append() function. This function isn't applicable to this example, however, as the "ingredients" array is declared as a constant on page 22, using a "let" statement. The .append() function returns an error, due to the immutability of the 'let' constant ingredients.

Mitchell T Schaff  Jan 17, 2024 
Printed Page 57
Last section

The code creating the dictionary does not match the graphical example.

James Leno  Jun 29, 2022 
Printed Page 80
Middle of page

\(n) should be \(d) in for loop code

James Leno  Jun 29, 2022 
Printed Page 112
Variadic code shown

The handwritten result for the line `let a = average(10, 21, 3.2, 16)` is shown as being 16.625, but that is incorrect. The correct average of those numbers is 12.55.

Steve Graff  Aug 25, 2022 
Printed Page 127
Switching with enums

The code shown at the top of page 127 displays errors, such as "Enum case 'dead' has no associated values" for the playerOneState definition. It relies on the earlier enum definition on page 125, but that appears to be missing the needed associated value definitions. I found that by defining and naming the associated values in the enum that this code compiles and runs fine:

enum PlayerState {
case dead(cause: String)
case blockaded(byEnemy: String)
case winner(score: Int)
}

func setPlayerState(state: PlayerState) {
print("The player state is now \(state)")
}

var playerOneState: PlayerState = .dead(cause: "crop failure")
switch(playerOneState) {
case .dead(let cause):
print("Player One died of \(cause).")
case .blockaded(let byEnemy):
print("Player One was blockaded by \(byEnemy).")
case .winner(let score):
print("Player One is the winner with \(score) points!")
}

Steve Graff  Aug 25, 2022 
Printed Page 128
Within the Exercise box

The first paragraph's second sentence is very long and gramatically incorrect. I suspect it's missing some punctuation, presumably a period (.) between the words choice and Once.

Anonymous  Aug 10, 2022 
Printed Page 129
The body of a function

The code for the function "welcomeCustomers" is missing both the empty parentheses in the definition, and also the closing parentheses at the end of the 'print' line. It should read as:

func welcomeCustomers() {
print("Welcome to the pizza shop!")
}

Steve Graff  Aug 25, 2022 
Printed Page 160
Be the Swift Compiler Solution

The solution states that H will work. However, H, as written, will not work, because the closure defined in H is named "slicePizza", but the call immediately after the closure definition is to "slicepizza". The variable name is not the same as the closure being called. This will result in a "Cannot find 'slicepizza' in scope" error.

Mitchell Schaff  Feb 02, 2024 
Printed Page 195
"Plant" class initializer

The initializer for the Plant class, as shown in the book, will not compile, as it does not include the code needed to set the value of the "type" property. As written, the code will generate a "'self.type' not initialized" error.

Mitchell Schaff  Feb 06, 2024 
Printed Page 293
Variable Declarations

In the "Sharpen your pencil Solution" for the DrinkCounterView, the three variables are defined without the "@State" attribute. This will result in a "Left side of mutating operator isn't mutable: self is immutable" error for each statement that increments the counters.

Mitchell Schaff  Feb 10, 2024 
Printed Page 293
Variable Declarations

Please ignore my errata suggestion for this page. I hadn't read the notes at the bottom of the solution.

Mitchell Schaff  Feb 10, 2024 
ePub Page 419
Code Magnets Solution

int redTeamScore: Int { ...
and
int blueTeamScore: Int { ...

for what stands the first "int" here?
shouldn't it be rather something like
var redTeamScore: Int { ...
and
var blueTeamScore: Int { ...

Thank you
Ansgar

Anonymous  Jul 05, 2023