If you encounter issues in the book, please post them to the forum for the appropriate chapter at forums.bignerdranch.com. Thank you!
countingUp
should be defined as a variable (and not a constant) in the section Literals and Subscripting:var countingUp = ...
. This is necessary because it is later mutated when callingcountingUp.append("three")
in the Instance methods section.
- In the section "Reference and Value Types",
ball0.particle.x = 1
should beball0.position.x = 1
.
- The
speechSynthesizer(_:didFinishSpeaking:)
method is correctly implemented to setisStarted = false
. However, later in the chapter the same method is incorrectly shown to callupdateButtons()
instead. - In the section "Common errors in implementing a delegate", the description of buggy behavior upon misspelling
speechSynthesizer(_:didFinishSpeaking:)
should state that the Start button will never be enabled (the Stop button remains enabled indefinitely). Additionally, the window can not be closed.
- In the For the More Curious section on Dependent Keys, the class
Person
has two problems: First, as documented earlier in the chapter, a class must subclass NSObject to participate in KVO. Thus, Person should subclass NSObject. Second, the computed propertyfullName
must have the explicit typeString
.
- In the section Storing the User Defaults, the text says that "you will need to make the app delegate the delegate of the text field". As shown correctly in the code listing that follows, it is the main window controller that should be the delegate of the text field. Later, the text says to open
MainMenu.xib
. Instead, you should openMainWindowController.xib
.
- In the section Improving Hit Detection, the
pressed
property is used to indicate whether the user actually clicked on the die. ThemouseUp(_:)
method (from the previous section entitled Click to Roll), however, does not checkpressed
before callingrandomize()
. As such the if expression inmouseUp(_:)
should read:theEvent.clickCount == 2 && pressed
.
- In the section on Ambiguous Layout, on page 375, the reader is instructed to add a call to
visualizeConstraints(_:)
at the end ofapplicationDidFinishLaunching(_:)
. The line above, shown for context, is a call toaddConstraints(_:)
, but it should beNSLayoutConstraint.activateConstraints(verticalConstraints)
.addConstraints(_:)
is the old way of doing this; it has been noted as deprecated in Apple's headers.
- In
EmployeesPrintingView
, theinit?(coder:)
initializer callsassertionFailure()
. This should be changed tofatalError()
. The reason is that with optimization enabled, such as in a release build, the compiler leaves out assertions. The Swift compiler knows this and in order to ensure that an object is fully initialized, considers it an error. Calls tofatalError()
are not ignored, however.
-
In the code snippet demonstrating using
NSXMLDocument
the result of the calls tonodesForXPath(_:error:)
, is cast usingas [NSXMLNode]
. Because the type of this API presently returns[AnyObject]!
, in the eyes of the Swift compiler this cast could fail. As such it must be cast usingas!
, like this:nodesForXPath(...) as! [NSXMLNode]
. -
In
ScheduleFetcher
, thecourseFromDictionary(_:)
method instantiates anNSDateFormatter
and assigns a var to reference it:var dateFormatter = NSDateFormatter()
. ThedateFormatter
reference should never be changed to refer to a different object, so it should be alet
instead:let dateFormatter = NSDateFormatter()
. -
In
ScheduleFetcher
, the same error code (1
) is used twice. There should be a different error code for each type of error. The error code for the second error ("Bad status code") should have code2
:let error = self.errorWithCode(2, localizedDescription: "Bad status code \(response.statusCode)")
.
- In the section "Refactoring for Testing" where the contents of
fetchCoursesUsingCompletionHandler(_:)
is cut and pasted toresultFromData(_:response:error:)
, the lineresult = .Success([])
should readresult = self.resultFromData(data)
. Cutting and pasting avoids this problem.