Errata - iOS Programming (7th Edition)

For collecting errors found in the 7th Edition.

I believe there is a bug in the code presented for updateTags() in the Photorama app, page 469. Details are here:

@gc3182 – Good catch! And perfect fix.

We’ll get that fix in for the next printing. We’ll also update the online solutions, along with adding a comment explaining the fix (since the 1st printing obviously won’t have the fix in place).

1 Like

Small typo inherited from the 6th edition on page 443’s description of the object graph: objects can be thought of as nodes, and the relationships as edges in a mathematical graph (instead of vertices).

My read of the Apple documentation gives a different picture than Figure 13.5. Are you sure Unattached->Suspended and Foreground Inactive<->Suspended (without going through Background) are possible? I also thought there should be an arrow from Background->Unattached in some circumstances.

Chapter 20, page 402:

Create a new Swift file called Photo and declare the Photo class with properties for the photoID, the title, and the remoteURL. Finally, add a designated initializer that sets up the instance.

However, there’s no designated initializer, neither in the book or the solution

Chapter 18, page 374 (pdf version)

The imageButtons property stores the images.

The images property stores the images

Thanks for calling this out, Pierre.

I’m using an eBook so no page numbers. But as Pierre said, in the paragraph above Listing 20.16 it instructs us:

Create a new Swift file called Photo and declare the Photo class with properties for the photoID, the title, and the remoteURL. Finally, add a designated initializer that sets up the instance.

However, the code in Listing 20.16 has a fourth property for dateTaken which the text above does not mention:

import Foundation

class Photo {
    let title: String
    let remoteURL: URL
    let photoID: String
    let dateTaken: Date
}

And Listing 20.16 does not include the designated initializer which the instructions above tell us to create. Furthermore, as Pierre pointed out, the provided solutions files for this chapter have also omitted the initializer.

Here is the code I wrote for this step in the instructions, which includes an initializer:

import Foundation

class Photo {
    let title: String
    let remoteURL: URL
    let photoID: String
    let dateTaken: Date
    
    init(title: String, remoteURL: URL, photoID: String, dateTaken: Date) {
        self.title = title
        self.remoteURL = remoteURL
        self.photoID = photoID
        self.dateTaken = dateTaken
    }
}

I’m reading the book, via Safari Online Bookshelf so I don’t have exact page numbers.
In Chapter 3 under heading Views & Frames there is a code snippet like the following:

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let firstFrame = CGRect(x: 160, y: 240, width: 100, height: 150)
        let firstView = UIView(frame: firstFrame)
        firstView.backgroundColor = UIColor.blue
        view.addSubview(firstView)
    }
}

When you try this code you will get an error.
The view object is not able to be referenced this way. I tried this.view (couldn’t remember how Swift refers to the current object) and had to search to find the answer.
The last line should be:
self.view.addSubView(firstView)
self is not mentioned in the text before this point so it was a bit confusing.
Also, the code download does not include this sample code in it so I couldn’t verify what the code actually did to get the ref to the view object.
thanks
UPDATE: This is odd, because now, later, after a successful build I was able to remove the self. before the view object and the app builds fine. Maybe this is an issue when the project is first created or something?

(I am reading both printed and Kindle versions) I realized that Fahrenheit to Celsius conversion is quite handy so I moved the localized WorldTrotter version of the Chapter 7 app to my iPhone for personal use (I travel overseas sometimes). When running on my iPhone via Xcode debugger the app works in its entirety, so far so good. When launching the app with the lightning cable disconnected (or just by tapping on the app) the app crashes when selecting the “Map” tab. I have pulled the crash report from Settings → Privacy → Analytics & Improvements → Analytics → “WorldTrotter-2022-01-15…” I have found a quite cryptic error related to some dictionary lookup failing in loadView of TabBar. So I instantiated the MKMapView in code of the MapViewController and the app started to work outside of the Debug session. Hmm… Obviously I jumped into the Emulator to see if the same crash can be experienced there, and sure enough the app crashed similarly. Then I moved the tabs to designate the Map a primary selection. Booya! The emulator has displayed a lot less cryptic error: "uncaught exception ‘NSInvalidUnarchiveOperationException’, reason: 'Could not instantiate class named MKMapView because no class named MKMapView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)’. Resolution: selected the top project in Project Navigator, selected WordTrotter in targets, selected the BuildPhases tab (to the right of “Info”) and added MapKit.frameworks under “Link Binary with Libraries (0 items)”. Voilà! I wonder if we need some mention of this in the 8th chapter on debugging?

Or perhaps instruct the reader to select “Maps” in Capabilities? ios - Could not instantiate class named MKMapView - Stack Overflow

…having continued the Localization chapter to the section “NSLocalizedString and strings tables” I realized that the authors are under impression that our MapViewController is initialized manually (in code) but for some reason my project’s MapView contains MKMapView in the Interface Builder (I must have rolled back some code after completing some of the Challenges in prior chapters). If I rolled back the manual configuration of MKMapView in error I apologize for the request above.