【发布时间】:2015-04-03 09:36:59
【问题描述】:
当我第一次启动我的应用程序时,我创建了 Show 对象,其中包含与 Feature 实体的多对多关系。仅在第一次启动我的应用程序后,它正确地存储了我的显示对象及其正确的功能。问题是,当我第二次启动我的应用程序时,它会从我的数据库中删除所有功能,尽管没有第二次访问数据库(我们每 5 天更新一次)。
这里是我用来存储的代码:
-(void)insertOrUpdateShow:(Show_fr*)show withObjects:(NSDictionary*)item forMoc:(NSManagedObjectContext*)context
{
if (!show)
{
show = [Show_fr MR_createInContext:context];
}
show.title = [item objectForKey:@"title"] ;
show.latitude = [item objectForKey:@"latitude"] ;
show.longitude = [item objectForKey:@"longitude"] ;
NSArray * features = [item objectForKey:@"feature"] ;
for (NSDictionary * featureDict in features) {
[show addFeaturesObject:[self createFeatureFromDictionnary:featureDict forMoc:context]];
}
[context MR_saveToPersistentStoreAndWait];
}
-(Feature_fr*)createFeatureFromDictionnary:(NSDictionary*)featureDictionary forMoc:(NSManagedObjectContext*)context
{
Feature_fr * feature = [Feature_fr MR_createInContext:context];
feature.icon = [featureDictionary objectForKey:@"icon"] ;
feature.label = [featureDictionary objectForKey:@"label"] ;
feature.value = [featureDictionary objectForKey:@"value"] ;
return feature;
}
确切地说,在第一次启动时,我的数据库中有 6 个节目和 127 个功能对象,而从第二次开始,我有 6 个节目,但有 0 个功能。
请问您知道如何解决这个问题吗?
问候
【问题讨论】:
标签: ios core-data magicalrecord magicalrecord-2.2