Software updates: March 6, 2020

Thank you for purchasing Swift in Depth. If you find errors not noted below, you can report them in the LiveBook Errata thread.

The following list shows updates made following a software update. Now, the book is compliant with Swift 5 instead of Swift 4.

Page xvii, Acknowledgements:

Please add the following list of reviewers to the end of paragraph four:

Also, I would like to thank the other reviewers: Alessandro Campeis, Ali Naqvi, Axel Roest, David Jacobs, Gustavo Gomes, Helmut Reiterer, Jason Pike, John Montgomery, Kent R. Spillner, Lars Petersen, Marcelo Pires, Marco Giuseppe Salafia, Martin Philp, Monica Guimaraes, Patrick Regan, Tyler Slater, and Weyert de Boer.

Page xxiii

Fifth paragraph, the word RxSwift should be Combine.

Sooner or later you'll run into map, flatMap, and compactMap on arrays, optionals,error types, and perhaps even functional reactive programming such as Combine.

Chapter 1, page 4

Section 1.3.1, line 2: delete the comma between the words version and needs.

In chapter 3, section 3.2.6. page 45

This correction has not been made in any format.

The line .dateComponents([.year], from: Date(), to: birthDate) should be .dateComponents([.year], from: birthDate, to: Date())

In chapter 7, section 7.3.1, page 133, in the note

The note mentions section 4.4, but that should be 7.4.

Chapter 9, Listing 9.10, page 175

The third line return int % 2 == 0

should be

return int.isMultiple(of: 2)

In chapter 9, Listing 9.41, page 194

Neither correction to this listing has been made in any format.

The last line in the code should be: let adrenalinePlan: TravelPlan = [adrenalineTrip: activities] // You can now create a TravelPlan from a dictionary.

There is a _ character missing in the third line after "first ," The line should be: self.trips = Dictionary(elements, uniquingKeysWith: { (first, _) in

In chapter 10, section 10.1.2, page 203

This correction has not been made to any format.

In the "Unique Keys" blurb, the line
For instance, if you pass [(name: "Miranda", count: 30, name: "Miranda", count 40)]
should be
For instance, if you pass [(name: "Miranda", count: 30, (name: "Miranda", count: 40)]
Note how I added both a ( and a :

Chapter 10, page 206

Delete all text following listing 10.9 through to section 10.3.2, including listing 10.10. All listing numbers beginning with 10.11 until the end of the chapter should be updated accordingly. For instance, listing 10.11 will be the new listing 10.10. To the end of the section (jut before section 10.3.2), add the following sentence:

Let's continue and see how you can embed this in a mapping operation to clean up your code.

In addition, the following in-text references should be updated:

  • page 207, last line, listing 10.12 should be listing 10.11
  • page 210, first line following the code snippet, listing 10.14 should be listing 10.13
  • page 214, third paragraph, listing 10.18 should be listing 10.17
  • In chapter 10, section 10.5.2, listing 10.15 (the new listing 10.14), page 212

    The line
    You return an optional String
    should be
    You return an optional URL.

    In chapter 10, page 227, answer for question 7

    This correction has not been made to any format.

    In the code let strideSequence = stride... etc The number 30 should be 100.

    Chapter 11, page 229

    The eighth point should be:

    Learning how to use errors dynamically with Result

    Chapter 11, page 231

    In the second line, the word tend should be tended.

    Not too long ago, developers tended to use...

    To the end of the second paragraph, delete the following phrase in the last sentence:

    ..., making it a non-official standard of error handling.

    The Result type, inspired by Rust's Result type and the Either type in Haskell and Scala, is a functional programmingidiom that has been taken on by the Swift community.

    Delete the last paragraph of this section (11.1).

    Chapter 11, page 236, Listing 11.7

    The right side of the expression in the second line should be:

    SearchResult.success("Tony Stark")

    let searchResult = SearchResult.success("Tony Stark")

    The term Value in the PARTIAL TYPEALIAS note, should be Success:
    The typealias still has a Success generic for Result,...

    Chapter 11, page 237, Listing 11.9

    The next to the last line is a let statement. Replace the right side of that expression with the following:


    let result = SearchResult<JSON>.failure(.underlyingError(error))

    Chapter 11, page 241, Listing 11.11

    The last line of code should be:

    return SearchResult.success(jsonDictionary)

    Chapter 11, page 244

    In the third line of section 11.3.4, add mostly just before focuses.

    ...and your code mostly focuses on the...

    In the second line of section 11.4, the term Result should be code font.

    each failure into a Result holding a single

    In the note at the bottom of the page, the term Value should be Success.

    NOTE Since we aren't interested in the value, you can define the Success type of Result to (), also known as Void or unit.

    Chapter 11, page 245

    The caption for listing 11.13 should be "Returning a specific error type."

    Delete the comment ```swift at the top of listing 11.13.

    There's a space missing after the word to in the third line following llisting 11:13:
    ...there's a call to moneyAPI.transfer(amount:, from:, to:),...

    The caption for listing 11.14 is "Returning multiple error types."

    Remove the word swift from the first line in listing 11.14.

    Chapter 11, page 246

    Line two in paragraph two contains a pre-production notation for italics, the / character. Remove those characters and italicize the words between.

    ...we state that Error conforms to itself.

    The caption for listing 11.15 is "Using the catching initializer on Result."

    Remove the word swift from the first line in listing 11.15.

    In the last line on the page, add a comma after the word listing.
    For example, in the next listing, we...

    Chapter 11, page 247

    The caption for listing 11.16 is "Getting the value out using the get method."

    Remove the word swift from the first line in the listing.

    Chapter 11, page 248

    The / characters in the third line are a pre-production notation for italics. They should be removed and the text between should be italicized.

    ...uses another so-called functional combinator for error...

    Figure 11.6 is missing. It should follow the second paragraph and be referenced as figure 11.16.

    When you use flatMapError, you can produce a successful resultfrom an error (see figure 11.6).

    The listing caption for listing 11.17 is "Error recovery using flatMapError."

    Remove the word swift at the beginning of listing 11.17.

    Chapter 11, page 249

    There should be an empty line below the "}" symbol, above the loadWeatherReport { (result... line.

    Chapter 11, page 250

    The reference to listing 11.22 in the second line should be listing 11.19.

    Chapter 11, page 253

    The word Error in the second line should be code font.

    In the fifth bullet under Summary, map and, should be removed:

    By using map, mapError, flatMap, and flatMapError, you can cleanly chain transformations of your data while carrying an error context.

    Delete the ninth bullet.

    Chapter 12, page 276

    Remove section 12.7.2 completely and update section heading 12.7.3 to 12.7.2 and 12.7.4 to 12.7.3.

    Chapter 13, listing 13.9, page 290

    API(session: session) should be WeatherAPI(session: session).