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!
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With