Errata for SwiftUI by Tutorials 4th Edition

Creating this topic to catch any typos and bugs in the 4th Edition of SwiftUI by Tutorials.

In book page 153 it says

SwiftUI doesn’t support putting a targetEnvironment() condition within the modifiers to a view

On the last Xcode version it does.

Chapter 15. This is a “twofer” since prior experience has taught me not to expect a reply, and three notes without a reply on this site gets you banned from any further posts (or at least that was the case when I was posting to the Errata topic for the 3rd edition). :slight_smile:

#1) I’m hitting the highlights of the changed sections, so this issue may have started in prior chapters. In FlightData.swift, the functions refreshFlights() and searchFlightsForCity(city:) both call Task.sleep(nanoseconds:) without a do/try/catch framework. The code doesn’t compile as-is.

#2) In Section 15.2, we are instructed to add the method lastUpdateString(date:) to FlightStatusBoard.swift. We are then instructed to call this method with Text(lastUpdateString).font(.footnote). There are a couple problems here. For one, the method requires a date: parameter, but then ignores it and supplies its own Date() object in the return statement. For another, the code where the method is called doesn’t supply the required parameter in the call. As given, this code does not compile.

[UPDATE] Regarding #1 above, I now realize (moving on to another chapter), that the code does compile. There’s a compiler warning 'sleep' is deprecated: replaced by 'Task.sleep(nanoseconds:)'. I must have fiddled with it, because it turns out that if you use that method signature, it can throw, but if you use the Task.sleep() signature, as given in the code, it does not.

1 Like

To remove the editor warnings, I wrapped the sleep task in a do try catch:
do {
try await Task.sleep(nanoseconds: 3 * 1_000_000_000) // Three seconds
} catch {
print(“refreshFlights func error”)

1 Like

Thanks. That’s exactly what I did too.

In chapter 17, section Using alerts as action sheets, there is this comment: Add the following state to the top of the view after showFlightHistory:

This piece of code is not yet in the project, as we write it in the following section Showing a popover

This topic was automatically closed after 70 minutes. New replies are no longer allowed.