I took some extra time after family departed before I got back into 100 Days of SwiftUI. For those keeping track, I am on Day 54. I took extra time with the challenge on Day 47, Habit Tracker, not because it was difficult, but because I really wanted to pull together the concepts and try a couple of new things.
One of the new things was adding buttons views in a list row. Turns out there is a secret to making this work. You have to read the documentation or get a bit lucky on StackExchange. I really don't know how people coded before the internet. Oh yeah, I remember. I RTFM. Anyhow, the problem was that tapping on the button in the list row, just selected the row. The button press was not detected. Turns out for the button press to be recognized, the .buttonStyle must be anything other than .automatic, the default. My thanks to Ramis who provided the answer. It has 312 likes (at the moment) so I think a great many others have searched for this answer.
The other issue was crafting an input screen that also served as a detail view. The former was reached by an add button, sliding up a sheet. The latter via tapping on the list row of an existing habit that was a NavigationLink to a detail view. The two cases were differentiated by passing in the selectedHabit. In the case of adding a new habit, the selectedHabit was nil. In hindsight they certainly could have been two different views, but I enjoyed working out how to do it with a single Swift view.
Anyhow, I'm currently getting an introduction to SwiftData on Day 54 and enjoying replacing CoreData with all its quirks. I'm too new to SwiftData, but I'm sure I'll be cursing its particular quirks soon enough.
(LU8)
No comments:
Post a Comment