.sqlite和.storedata有什么区别 [英] What is the difference between .sqlite and .storedata
问题描述
当您使用核心数据在Xcode上启动新的iOS项目时,它会使用扩展名 .sqlite
初始化数据库。当为OSX的新项目做同样的事情时,数据库的扩展名为 .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.
推荐答案
iOS上的CoreData仅支持sqlite持久存储。 OS X上的CoreData支持多种格式,包括sqlite和xml,默认持久存储是基于xml的。因此.sqlite是CoreData的一个sqlite持久存储,而.storedata是一个xml持久存储。
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.
为了扩展答案,sqlite持久存储允许模型部分和递增加载,而xml持久存储只允许(需要)模型被大量加载。默认值的差异可能是由两个平台上不同的内存可用性来解释的。
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.
要将默认代码切换为使用sqlite而不是xml,请编辑 persistentStoreCoordinator
并更改:
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]) {
至:
NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"Foo.sqlite"];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
if (![coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:nil error:&error]) {
这篇关于.sqlite和.storedata有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!