|
I have the NavigationLink load a the activity details view. The view loads fine, but as soon as I use the stepper to increment or decrement the completion count the details view exits and I'm back at the main ContentView. Furthermore, the completion count does not save. Any ideas as to what I'm missing here? This is ContentView.swift:
And this is ActivityDetailView.swift:
|
|
After some experimentation the problem seems to be that I can't overwrite or remove any elements from activities.activityList. I can append, but if I try to assign over top of an element or use .Remove(), the view silently crashes and reverts to the main ContentView. Not sure how to fix it. |
|
Can you show the rest of your code? Like, the |
|
Here's the Activities class:
AddActivityView works, but that's consistent with what's happening in ActivityDetailView since append is all that's used in AddActivityView. Here it is:
|
|
Got some help in r/iosprogramming. I think the hints for the challenge are perhaps out of date and misleading based on this article which explained how to do it: https://www.swiftbysundell.com/articles/bindable-swiftui-list-elements/ You don't even have to pass the class holding the collection to the view or mess around with indices. Here's the solution:
|
|
This does work for me after building but Im curious what youre passing into the preview provider below in your detail view. In the moonshot lessons, we passed in a default key of 'armstrong' into the astronaut view to satisfy the call to the previewer. Similarly, I try passing some default data from my habit struct (HabitItem) where we define the properties for a habit (Activity in your case) but am met with:
So far Iver tried using |
|
You can satisfy it with a constant binding. It has fixed values, it can't be changed in the UI, but it comes in handy for previews.
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.