ios - 核心数据 - countforfetch 总是为空数据库返回 1

标签 ios core-data xcode5.1

我看过这个link其中 countforfetch 始终为 1。但没有给出解决方案。

当我按照链接中给出的方式执行获取请求时,它会为我提供我每次都将要保存的数据。因此,由于它已经存在,因此不会重新保存。所以数据库是空的。但令人惊讶的是,数据出现在桌面上。

这似乎是一个非常奇怪的行为。有人可以帮忙吗?

这是我的代码

  NSFetchRequest *fetchRequest12 = [[NSFetchRequest alloc] init];
    NSError *error;
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"orderNumber = %@",orderList.orderNumber];
    [fetchRequest12 setPredicate:predicate];

    [fetchRequest12 setEntity:[NSEntityDescription entityForName:@"OrderList" inManagedObjectContext:appDelegate.managedObjectContext]];
      NSLog(@"The fetch was successful! %@", [appDelegate.managedObjectContext executeFetchRequest:fetchRequest12 error:&error]);

    if ([appDelegate.managedObjectContext countForFetchRequest:fetchRequest12 error:&error] ==0 ) { // Somethings to be done 
}

最佳答案

如果您希望提取请求忽略您在 MOC 中所做但尚未保存的任何更改,请将 setIncludesPendingChanges: 设置为 NO。默认情况下会获取所有未保存的更改(因此您会在 UI 中看到未保存的更改)。

关于ios - 核心数据 - countforfetch 总是为空数据库返回 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22910755/

相关文章:

ios - 访问 iCloud 驱动器上的应用程序数据

swift - CoreData 不持久?

ios - 如何将用户选择的颜色设置为整个 IOS App 的背景色?

objective-c - -initWithContentsOfFile : for an NSMutableArray

iOS:将UITableView的起始索引从0改为1显示数组内容

ios - 隐式转换失去整数精度Xcode 5.1

objective-c - Xcode 5.1 升级后架构链接错误

ios - 如何防止加载 meteor.local(使用 phonegap 构建 ios 应用程序时)

ios - 什么时候应该使用 iOS 中的各种存储机制?

ios - Xcode 5.1 : missing required architecture arm64