Nondescript crash in my SwiftData app when trying to access a dictionary

I'm making an app for a school project in SwiftUI and SwiftData. It's a habit tracker and I have a SwiftData class for persisting basic habits. Where the problem started is that I'm trying to implement a way to track when a certain habit was completed. I deleted my existing instances of the class and added a dictionary under self.isCompleted as [Date:Bool] (so 3rd of August = true etc.) I then made a function in the HabitView (where you can see the details of the habit) that checks if the current date in the dictionary is true and if so doesn't show the option to complete the habit. Problem is now that whenever I make a habit, and go into view it, the app instantly crashes with the only error being a "SIGTERM". I thought it was crashing because it was trying to check something that wasn't there (empty dictionary bc new habit) but I've tried compensating for that and it's still crashing with the all-ambiguous error. Anyone know what I can do now? Will provide code upon request if needed. Honestly at this point I might just kinda try something completely different for keeping track of completion.
2 Replies
finlay ☀
finlay ☀15mo ago
Weird. In the interactive preview I can loadup the habit view just fine. It even understands that there was nothing to check and so the button displays "Mark as done"as it should. Commented out the completion check function and yup simulator runs just fine
nouun
nouun15mo ago
Not sure what the issue is but another way of storing the data could just be an array of dates when it was completed and then append to that array when completed or pop when marked as incomplete. SwiftData is a very new framework and it has many bugs so it may be an underlying issue with SwiftUI, I know when I was trying it out I was having so many issues that I just stopped using it completely.
Want results from more Discord servers?
Add your server