【发布时间】:2012-04-12 03:52:21
【问题描述】:
创建新项目的 1.0 版即将结束。我第一次使用 coredata。
应用程序仅使用 1 个模型,所有数据将由用户提供(因此我不使用应用程序加载任何数据)。
当然,我已经在为不同分支上的应用程序进行更新,并在未来看到数据模型的一些变化。模型上的更改将仅包括:
- 添加实体
- 向现有实体添加属性
- 实体之间没有任何关系。
我已阅读:iPhone app with CoreData 从那里我继续到:Lightweight Migration,在那里我读到了 coredatas 能够在更改很小的情况下自动更新其模型(如果我没看错的话,我的更改包含在其中)。
在苹果迁移文档中我找到了自动迁移的代码:
NSError *error = nil;
NSURL *storeURL = <#The URL of a persistent store#>;
NSPersistentStoreCoordinator *psc = <#The coordinator#>;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
BOOL success = [psc addPersistentStoreWithType:<#Store type#>
configuration:<#Configuration or nil#> URL:storeURL
options:options error:&error];
if (!success) {
// Handle the error.
}
我的问题如下:
- 我将把这段代码放在哪里?我现在找到了关于它的更多信息
- 我是否认为此代码仅在应用程序的更新版本中是必需的?
- 我是否需要对我的 1.0 版应用程序进行任何其他准备工作以允许以后对 coredata 进行主题化和更新,或者我不必在第一个版本中考虑这一点?
【问题讨论】:
标签: iphone objective-c ios core-data core-data-migration