Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between .sqlite and .storedata

When you start a new iOS project on Xcode using core data, it initializes a database with the extension .sqlite. When you do the same thing for a new project for OSX the database has the extension .storedata.

Is there any difference between the two? thanks.

like image 505
Duck Avatar asked Feb 14 '23 04:02

Duck


1 Answers

CoreData on iOS only supports an sqlite persistent store. CoreData on OS X supports multiple formats including sqlite and xml, with the default persistent store being xml-based. Thus .sqlite is an sqlite persistent store for CoreData, whereas .storedata is an xml persistent store.

To expand on the answer, an sqlite persistent store allows the model to be partially and incrementally loaded, whereas an xml persistent store only allows (requires) the model to be loaded en masse. The difference in defaults is probably explained by the differing memory availability on the two platforms. With much more memory available on a typical Mac, the overall performance is enhanced by loading everything at once.

To switch the default code to use sqlite instead of xml, edit persistentStoreCoordinator and change:

NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"Foo.storedata"];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
if (![coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:nil error:&error]) {

to:

NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"Foo.sqlite"];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
if (![coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:nil error:&error]) {
like image 134
David Berry Avatar answered Feb 16 '23 03:02

David Berry