|
I completed this successfully. However as i refactored my code on the Activity View file (which shows the name of the habit, its description and allows you to increase how many times you've completed it), i ran into the below error: ForEach<Array<Habit>, UUID, NavigationLink<Text, Never>>: the ID xyz occurs multiple times within the collection, this will give undefined results! This will happen if I increase the completion count on the activity before getting its index (required in order to insert a copy of the updated activity struct with the new completion count). The effect is that if I run the app this way, once i go into the detail view and increase completion count, the above error shows in the console. Then if i go back to the main content view i might run into another copy of the same detail view, and now the top entry on my list has the same as the one i just modified Relevant code ContentView:
Activity View that works:
Activity View that doesn't work:
Struct:
I sort of understand that the issue is a result of modifying the original Habit and breaking how the id: works in the ForEach, something goes wrong with its UUID, but was hoping someone here can explain the issue more concretely. Thanks! |
|
I have been known to provide not-quite-accurate information. But maybe this can help? HashLook at the defined properties in your Your Look at your code. In the example that works, you find the matching finger print first, then you change it, then insert the change back into the collection. In the code that "doesn't work" you change the Paste this code into Playgrounds and run it.
Keep Coding |
|
Thank you so much Obelix!!! I really appreciate your taking the time to show me this through all that code, I ran it and it showed me exactly where i was going wrong. Also going back to my code I added a printout which showed me how in the wrong sequence, the index result is indeed coming back as nil, and how my nil coalesce handling (index ?? 0) explains why my first item on the list was getting 'duplicated' over the first entry of the list |
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!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.