|
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 Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!
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.