【问题标题】:Core data not inserted value in entity in iOS 9核心数据未在 iOS 9 中的实体中插入值
【发布时间】: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


    【解决方案1】:

    您注释掉了对save 的调用。这就是为什么您的数据没有被持久化的原因。

    【讨论】:

    • 现在,我重新检查它,数据被插入到 iPhone 模拟器中,但没有插入到 iPod touch(iOS 9.01)中
    猜你喜欢
    • 2016-01-25
    • 2017-05-22
    • 2017-07-12
    • 2015-12-21
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    相关资源
    最近更新 更多