Group Group Group Group Group Group Group Group Group

Chapter 10, Adding an action sheet

In the section in Chapter 10 on adding an action sheet, there is a line in the code that checks if flight.status is ontime or delayed. However, it is flight.flightStatus, not flight.status that is used to display the rows. FlightStatus knows whether flights have departed or not. The result is that even departed flights will display the “check in for flight” button since the list knows it has departed but the button code for the check in button does not.

If I try to change the lines to check if flightStatus is ontime or delayed, however, the app won’t compile due to a problem with the .leading on the VStack or the padding on the font headline. (Perhaps I am just too much of a newbie to understand why this is so.)

I realize this is just a test app, but it still doesn’t seem right to me when you are trying to only add a check in button for appropriate situations.

In a real app you would have more complex logic so that a departed flight would not be allowed to check in. It was a case of me trying to balance keeping the code somewhat realistic, but not adding too many cases for something that’s not the topic at hand.

My guess on your compile error is that you had a syntax error of some sort. SwiftUI error messages are often pretty misleading and will often flag something like alignment or constant values when the error is somewhere else. The enum for flightStatus is defined as a String so you’d need a comparison that would be something like:

(flight.flightStatus != "Cancelled" && flight.flightStatus != "Departed")