Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData & Data Protection

So I am working on a app which stores user information with CoreData framework locally. The information can be sensitive, so I am thinking how to protect the information stored to the data base. In Xcode dashboard, under the capabilities tab, I found this Data Protection switch:

Anyone knows how this works? If I turn on the switch will Xcode encode my CoreData files automatically? Or how to implement this protection on my CoreData files? Appreciate your time and patient. Thank you!

like image 522
Michael Dai Avatar asked Dec 21 '16 00:12

Michael Dai


People also ask

What is Core Data used for?

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.

What is Core Data in iOS Swift?

Overview. Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.

Should I use Core Data?

The next time you need to store data, you should have a better idea of your options. Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.

Does SQL use Core Data?

Even though Core Data knows how to use a SQLite database as its persistent store, that doesn't mean you can hand it any SQLite database. The database schema of the SQLite database used by Core Data is an implementation detail of the framework. It isn't publicly documented and liable to change.


1 Answers

As per Apple documentation, the Data protection is enabled automatically when the user sets an active passcode for the device. The system encrypts and decrypts your content behind the scenes. These processes are automatic and hardware accelerated. But still we can set the file protection level options programmatically by using none, complete, completeUnlessOpen and completeUntilFirstUserAuthentication

let options = [NSMigratePersistentStoresAutomaticallyOption:true,
                           NSInferMappingModelAutomaticallyOption:true,
                           NSPersistentStoreFileProtectionKey: FileProtectionType.complete] as [String : Any]
            try persistantStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storeURL, options: options)

Refer this link to know more information on different types of options.

like image 66
Ganesh G Avatar answered Sep 17 '22 19:09

Ganesh G