JSON Core Data favorites

I am working on the project similar to SwiftUI tutorial . I have a "favourites" button done, but every time app restarts, list of marked items is gone. I understand Core Data is the way to go, but as each item (struct) has a lot of information attached (pictures, text etc.) and "favourite" is just one Bool. I am not sure how to use Core Data and not to overload it. Do I need to use Core Data to save every item with all information(pictures, text etc.) or just bool and some reference to e.g. "id"?
Answered by Claude31 in 668473022
Tell if you have any problem in doing so.

A simple way to do it is to create a dictionary, with ID as key and a Bool value for favorite.
Then save as UserDefaults.

See a detailed example here:
https ://cocoacasts. com/ud-4-how-to-store-a-dictionary-in-user-defaults-in-swift

Don't forget to close the thread once solved. Good continuation.
If I understand your question correctly.

You have 2 things :
  • the data for all the information you save in Core Data

  • the status of some as favorite.

This may be stored in the core data
or simpler in suerSettings (with a reference to the data ID)
I have a static data from JSON. Data doesn't change, just the flag with each item ( is favourite : Bool ). I am looking at the UserSettings as you suggested, I will need to play around with it. Thank you for your help.
Accepted Answer
Tell if you have any problem in doing so.

A simple way to do it is to create a dictionary, with ID as key and a Bool value for favorite.
Then save as UserDefaults.

See a detailed example here:
https ://cocoacasts. com/ud-4-how-to-store-a-dictionary-in-user-defaults-in-swift

Don't forget to close the thread once solved. Good continuation.
userDefaults did the job. Thanks for your suggestion. I also looked here:
https ://www.hackingwithswift. com/books/ios-swiftui/letting-the-user-mark-favorites
JSON Core Data favorites
 
 
Q