【发布时间】:2023-04-05 19:01:02
【问题描述】:
我在应用程序中使用 coredata。它在 iOS 8.4.1 中完美运行。昨晚我将我的 iPod 更新到 iOS 9,我发现该值没有插入 coredata。
我删除了 iOS 8.4.1 中由 coredata 生成的类,并在 iOS 9 中生成了新类,我观察到每个实体都生成了 2 个新类。假设我有一个实体 AllCategory,它有实体 id、name、imageUrl。我在 iOS 8.4.1 之前的工作代码是
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"AllCategories" inManagedObjectContext:context];
NSError *error;
NSUInteger count = [context countForFetchRequest:request error:&error];
if (count==0)
{
for (CategoryList *temp in catList)
{
AllCategories *book = [NSEntityDescription insertNewObjectForEntityForName:@"AllCategories" inManagedObjectContext:context];
//[book setBid:[NSNumber numberWithInt:[temp.cat_id intValue]]];
[book setCatid:[NSNumber numberWithInt:[temp.cat_id intValue]]];
[book setCatName:temp.cat_Name];
[book setImage:temp.cat_Image];
//[self.managedObjectContext save:nil];
NSLog(@"temp.cat_Name=%@---%@",temp.cat_Name,book.catName);
}
}
此代码也适用于 xCode 7 和 iOS 8.4.1
【问题讨论】:
标签: objective-c iphone core-data ios9 xcode7