Chapter 1 - Section 4 (Challenge part)

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

I think this is outdated right? now we can use targetEnvironment() condition within the modifiers to a view.

The latest SwiftUI does allow this. The following code will now work. I’ll update this in the next edition of the book.

HStack {
  Spacer()
  Text("\(memory)")
    .accessibility(identifier: "memoryDisplay")
    .padding(.horizontal, 5)
    .frame(
      width: geometry.size.width * 0.8,
      alignment: .trailing
    )
    .overlay(
      RoundedRectangle(cornerRadius: 8)
        .stroke(lineWidth: 2)
        .foregroundColor(Color.gray)
    )
    #if targetEnvironment(macCatalyst)
      .gesture(doubleTap)
    #else
      .gesture(memorySwipe)
    #endif
  Text("M")
}.padding(.bottom).padding(.horizontal, 5)