Missing initializer

This was already called out in the errata, but I think it’s a major omission so I wanted to mention it here too, in case anyone gets stuck on this step.

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. 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
    }
}

You need an initializer at this point in the project to avoid a compiler error. Although later in this chapter, in Listing 20.17, you will make this class conform to the Codable type alias which apparently satisfies this compiler warning. Still, it may be confusing to some people that the initializer we were instructed to create here is missing from the code in the book.