Errata

Learning Swift

Errata for Learning 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
ePub Page ch 3
Initialization and Deinitialization

I'm using Swift 3.0. So far I haven't run into much code in your text that requires substantial modification, and I'm finding the text very helpful in learning Swift (or I think I am ... we'll see if I can actually do anything useful with it).

However, in the Chapter 3 example under "Initialization and Deinitialization", your code has:

var example : InitAndDeinitExample?

// using the designated initializer
example = InitAndDeinitExample() // prints "I've been created!"
example = nil // prints "I'm going away"

I think the destructor is incorrect: setting example to be nil doesn't invoke the deinit procedure. In fact, the message that should be emitted by deinit() isn't printed (and it appears that the procedure isn't invoked). The message *is* emitted as Playground reaches the end of the code body -- presumably because on exiting the system deallocates anything left around.

And oddly enough, removing "example = nil" and invoking the deinit with
example.deinit()
causes a Playground crash. (!)

1) Am I right that setting example to nil doesn't actually destroy the "example" object?
2) What's the right way to deallocate the object?

David Todd  Dec 02, 2016 
PDF Page 24
The showAlert() function

XCode complains about the last line in the function:
self.helloButton.setTitle("Test!", forState: UIControlSate.Normal)

The error is:
Use of unresolved identifier 'UIControlState'

There's no obvious way to work around this problem, and there's no updated code for this sample in the git repo for the book.

mpounsett  Feb 27, 2017 
ePub Page 25 of 286
The showAlert() function

xCode 7.1.1 complained about the use of "var" to define the
"alert" object. It compiled with warning:

Variable 'alert' was never mutated; consider changing to 'let' constant

Everything worked as described. I change "var" to "let" and
got a clean compile.

Larry Breyer  Nov 29, 2015 
Printed Page 62
class Vehicle code

the code
return "A \(self.color) vehicle"
in the playground outputs
"A Optional("Red") vehicle"
if one adds the ! to the optional var color
return "A \(self.color!) vehicle"
the output is as displayed in the book
"A Red vehicle"

kee nethery  Sep 01, 2016 
Printed Page 62
class Vehicle code

the code inside class Vehicle
print("Traveling at \(maxSpeed) kph")
in the playground when called by the code
redVehicle.travel()
displays a result of
Vehicle
instead of the published result of the print of
"Traveling at 90 kph"

What is the correct code for the playground to print what you say it should print?

kee nethery  Sep 01, 2016 
Printed Page 63
sample code

in the playground
example = InitAndDeinitExample() // prints "I've been created!"
displays
InitAndDeinitExample

and
example = nil // prints "I'm going away"
displays
nil

and
example = InitAndDeinitExample(text: "Hello")
displays
InitAndDeinitExample

how does one try the sample code and get the results published in the book?

kee nethery  Sep 01, 2016 
ePub Page 78
Chapter 2, Working With Strings, tip box

“In other languages like C and Objective-C, the == operator checks to see if two values are equal, or if two variables refer to the same location in memory. If you really do want to see if two string variables refer to the same object, you use the === operator (note that it’s three equals signs, instead of two):
if string1 as AnyObject === string2 as AnyObject {
print("The strings are the same object")
}
AnyObject in Swift means “any object, of any type.”

Excerpt From: Paris Buttfield-Addison. “Learning Swift.” iBooks.

String is a value type, therefore cannot be casted to AnyObject.

Galius Kardas  Jun 03, 2016 
PDF Page 78
Code comments, mid and lower page

A minor issue, but I believe the comments within the withdraw and deposit functions are flipped.

The .pdf shows:

func deposit(amount: Float) throws {
// Ensure that we're trying to withdraw a non-negative amount

and func withdraw(amount : Float) throws {
// Ensure that we're trying to deposit a non-negative amount

and it should be:

func deposit(amount: Float) throws {
// Ensure that we're trying to deposit a non-negative amount

and

func withdraw(amount: Float) throws {
// Ensure that we're trying to withdraw a non-negative amount

Jim M.  Aug 20, 2016 
ePub Page 89
3rd paragraph

On page 89, range operator, (..<) was mistakenly written as (<..) range operator. This creates the confusion that <.. is another range operator.

Jason  Jun 12, 2016