Errata for SwiftUI by Tutorials 1st Edition

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

1 Like

Chapter 1: do the naming conventions for the guessing and target colors need to be abbreviated? Its good practice to not do this for clarity and for the sake of an extra few letters may as well be written in full in my opinion.

Chapter 1: isn’t the body of the View protocol a property? A few times in chapter 1 it is referred to as a closure.

Hi Ray,

Is there plans for some chapters devoted to Apple Watch & Apple TV. Because as per the keynote SwiftUI helps in easily developing apps for those platforms as well.

Thank you & Regards
Ruptapas

@ruptapas We don’t have any plans to include chapters on Apple Watch & Apple TV in this edition of the book - but we can consider this for future editions. You can see the full list of chapters planned for the book here: https://store.raywenderlich.com/products/swiftui-by-tutorials

hi Piers: the letters r, g, b refer to the RGB color space, as does the app name RGBullsEye.

fair enough! fixed in Early Access 2 — thanks!

Awesome! Btw I did really enjoy chapter 1 so I hope I didn’t come across too negative. Really excited to get the completed book. Keep up the great work.
Thanks

thanks! keep up the great questions :grinning:

This is far from an error or something that is necessary, but in Chapter 2, I think it would help to briefly state why showAlert will revert back to false after the alert is dismissed. It seems small, but when you’re new to declarative programming, these small differences are pretty big!

thanks @sbcooney!

Just before you add the showAlert variable, I say the value resets to false when the user dismisses the alert, but I’m not sure what you mean by “why” … it’s so the alert stops being shown — do you think I should make that clearer?

I think it was really just the use of the word “reset” instead of set- as if it would be set somehow to its initial state when the window was dismissed instead of just being set to false by alert(ispresented:… .

1 Like

In Chapter 13, page 114 in the current version, the top code snippet shouldn’t have “if showDetails {” in it as that condition is replaced by ".offset(x: showDetails ? 0 : -UIScreen.main.bounds.width).

2 Likes

“When the details should not hidden, then the view shifts UIScreen.main.bounds.width — the width of the current screen — to the left, ensuring it is not visible.”

I believe it should start with “When details should be hidden, …”

Removing and combining animations:
Adding .animation(nil) between scale and rotation changes nothing - both effects still animated. Have you actually tried it? I just did (XCode 11 GM Seed).

1 Like

Thanks. I’ll work to get that updated for the next release.

Thanks! I’ll get that fixed.

The animation issue is a change in how the views interact from the beta where this was originally written. It causes the later animation to always be applied. I’ll rework this section for the next update. For now change the code so it looks more like this:

HStack {
  Text(showDetails ? "Hide Details" : "Show Details")
  Spacer()
  Button(action: {
    self.showDetails.toggle()
  }) {
    Image(systemName: "chevron.up.square")
      .scaleEffect(showDetails ? 2 : 1)
      .animation(nil)
      .rotationEffect(.degrees(showDetails ? 0 : 180))
      .animation(.easeInOut)
  }
}

BTW, it might be my own opinion but code snippets in the books (I’m reading SwiftUI and Catalyst) are just… awful, sorry. Style is almost unreadable – you copy/paste first it to xcode, then prettify, and only then it start having sense.

FlightBoardInformation.swift fails to render in Preview (Xcode GM Seed 2). The crash says:

Application Specific Information:
Fatal error: Accessing State outside View.body: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Monoceros_Sim/Monoceros-24.4/Core/State.swift, line 44

CoreSimulator 681.5.1 - Device: iPhone 11 Pro Max (1062039B-020C-4D62-B2D0-BD3BBD51A0B8) - Runtime: iOS 13.0 (17A577a) - DeviceType: iPhone 11 Pro Max

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x00007fff50a9c7ed specialized assertionFailure(::file:line:flags:) + 509
1 libswiftCore.dylib 0x00007fff50894a09 assertionFailure(:
:file:line:flags:) + 25
2 com.apple.SwiftUI 0x00007fff2bfefca6 State.location.getter + 230
3 com.apple.SwiftUI 0x00007fff2bfef6d7 State.getValue(forReading:) + 103
4 com.apple.SwiftUI 0x00007fff2bff02aa State.projectedValue.getter + 58
5 com.raywenderlich.MountainAirport 0x000000010c633d18 static FlightBoardDetail_Previews.$isPresented.getter + 168
6 FlightBoardInformation.2.preview-thunk.dylib 0x0000000114fcb038 static FlightBoardDetail_Previews.__preview__previews.getter + 232
7 com.raywenderlich.MountainAirport 0x000000010c633f08 static FlightBoardDetail_Previews.previews.getter + 56 (FlightBoardInformation.swift:77)
8 com.raywenderlich.MountainAirport 0x000000010c6340c9 protocol witness for static PreviewProvider.previews.getter in conformance FlightBoardDetail_Previews + 9
9 com.apple.SwiftUI 0x00007fff2c13d335 static PreviewProvider._previews.getter + 69
10 com.raywenderlich.MountainAirport 0x000000010c634126 protocol witness for static _PreviewProvider._previews.getter in conformance FlightBoardDetail_Previews + 54
11 com.apple.SwiftUI 0x00007fff2c13d609 static _PreviewProvider._allPreviews.getter + 25