|
This app seemed simple at first, but working with data is challenging my understanding more than I expected. I have the app is working other than the Habit counter increase/update: It's goving me an error I can't seem to decode. What am I doing wrong? This is my HabitDetailView
and these are my struct and class:
and of course, here's my error 🤨
Of course, using ?? and ! crashed the app. I would rather find the real mistake and learn to understand the error and stick in a quick fix anyway. |
|
Hi! Try to use
|
|
Thank you @ygeras. Please tell me if I understand this correctly:
When I am unclear about it, when the program is running, to get to this specific View one would need to have at least one item, the specifics of which would be pushed to this view when HabitDetailView is activated. So it would never be emtpy, because if the array of Habits was empty, then one could not click on a item and get details... so why handle it as an optional? Because HabitDetailView doesn't know all of this? |
|
The answer to your question is much simpler. You need to know how method of It's you, who knows that there is particular value available in the array but compiler does not, so to be save it returns Optional. As an example you could see what happens if we force unwrap the value, kind of situation if the method returned non-optional.
|
|
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.