What is the best way to save data on the device?

In swift UIKit

I want the best way to save data on the device So that the user can refer to it later Like notes, photos, and videos

Is she on Userdefaults or Core Data Or is there a better way to use it?

I am a beginner and you may not know a few things Because I worked to save notes, photos and videos on the Core Data, and I encountered problems, I could not view the video

I hope to answer for anyone who has any useful information, and I will be thankful to you

UserDefaults is great to save small size content (Bool, Int, String, Date). It is OK for short texts, arrays or dictionary of Bool, Int, String.

For large content, if you want to use UserDefaults, is is better to do it in 2 steps:

  • save each photo or video in a file
  • save the url of the file in UserDefaults

Hi allbdrii0,

I think that the correct place to save data on device it strongly depends on a large set of variables like: the data type you're trying to save, the amount of data, the architecture of you're app, etc....

In general, I always use these rules to choose where I can store my data:

  1. Keychain: store all sensitive data (like passwords, secret tokens, coins amount, in-app purchase status, ...);
  2. UserDefaults: store only small amounts of not sensitive data (user preference like the app theme or the app language);
  3. CoreData: store large (or potentially large) amounts of data or store data that is queried/filtered often.
What is the best way to save data on the device?
 
 
Q