Reputation: 51
I want to store how many days in a row the user has met their daily goal as an integer, and the date they first started this 'streak' of days.
I don't know whether Core Data seems a bit much for this simple functionality, however, I don't want a user to potentially lose their 'streak'.
Is User Defaults safe enough for this use case? Should I use UserDefaults or Core Data?
Upvotes: 1
Views: 840
Reputation: 1703
UserDefaults won't be cleared or removed unless the app is deleted (even app updates and backups are fine), so you're safe to persist data there which isn't considered sensitive.
In my opinion, UserDefaults seems to fit your situation the best!
Upvotes: 1
Reputation: 16341
You only require to store just two variables
which can be combined into a single struct
and stored as a single key/value pair in the UserDefaults
. CoreData
seems to be an over-kill for your situation. CoreData
is usually used to store large amounts of data. Say you had to store an array of information regarding each day, then you should definitely go for CoreData
. And FYI: Data stored in UserDefaults
are persisted just like the data stored in CoreData
, so you don't have to worry about losing the data stored in UserDefaults
.
Upvotes: 1