Local Data Storage Best Practices

I’m getting started on my app and I’m interested in best practices for data storage. To mitigate regulatory issues (it’s a medical app), the data collected in the app will only be stored on the phone. I’ve been doing some Googling but it’s unclear to me whether CoreData will automatically be uploaded to the cloud. I’ve also considered saving the data in a JSON file on the phone (not sure how to do that yet, still investigating). Using JSON would necessitate a serialization operation each time the data is changed and I don’t have a good handle on the amount to data that will be saved yet so that option is still up in the air (that’s why we use a data model, right :wink: ). So, I guess the questions are: Is CoreData uploaded to the cloud? If so, is there a way to disable that? Is CoreData encrypted? Same three questions for JSON files on the phone. Thanks!

Hi,

Core Data is only uploaded if you select Cloudkit when creating the project. The cloudKit check box changes NSPersistentContainer to NSPersistentCloudKitContainer. That is all I can see at any rate.

I believe you can also encrypt the sqlite file, but I have not explored that option since I don’t need it.

Blessings,
—Mark

1 Like

Hi,
Following this topic, I have a problem, I’m using core data to save some JSON files and save them to user defaults, now the issue is that every time I have an update on the json file, I cannot see the updates on the phone unless I uninstall the app and install it again.
Is there a better way to remove user defaults? or how can I update the JSON file an let the user see the changes?

You can save JSON files to the documents directory of the phone.

You should NOT be saving your JSON files in CoreData or in UserDefaults.

1 Like