简体   繁体   English

核心数据中缺少对象

[英]Objects missing from Core Data

Alright, I'm going crazy trying to figure this one out, so I figured I'd post it and see if anyone knew what was going on. 好吧,我想找出这一点要疯了,所以我想把它张贴出来,看看是否有人知道发生了什么。

I add entities to Core Data and retrieve them fine and everything displays perfectly in my app. 我将实体添加到Core Data并进行了很好的检索,所有内容在我的应用程序中均完美显示。 But for some reason when I use NSFetchRequest to get a list of all the entities of some type, it always returns one less object than there should be. 但是出于某种原因,当我使用NSFetchRequest获取某种类型的所有实体的列表时,它总是返回比应该少的一个对象。 I know the object is somewhere because my app can display data from it elsewhere in the app. 我知道该对象在某个地方,因为我的应用程序可以在应用程序的其他位置显示来自该对象的数据。 Also, I manually examined the sqlite file and noticed that it is also missing one object. 另外,我手动检查了sqlite文件,发现它也缺少一个对象。 How is this possible if my app is accessing the data? 如果我的应用正在访问数据,怎么办?

Here's the code I use to fetch the entities. 这是我用来获取实体的代码。 I use this code in many places throughout my app and it always returns one less object then there really is, but my app is still about to access it. 我在整个应用程序中的许多地方都使用了此代码,它总是返回比实际少一个的对象,但是我的应用程序仍将访问它。

NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MWLocationItem" 
                                          inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:nil];

Does anyone have any idea of what is going on? 有谁知道发生了什么吗? Please let me know if there's any other code you'd like to see. 如果您要查看其他代码,请告诉我。

1. I think that this is can be possible if you're ignoring error's on 1.我认为,如果您忽略错误的发生,这是可能的

[NSManagedObjectContext save:nil]

Try to use method below, to check if is everything okay 尝试使用下面的方法,检查是否还可以

[NSManagedObjectContext save:&error]

2. Another possible reason can be that you set includesPendingChanges property to fetchrequest 2.另一个可能的原因可能是您将includePendingChanges属性设置为fetchrequest

request.includesPendingChanges = NO;

If there's no correct answer :) Can you provide a bit more lines of source code? 如果没有正确的答案:)您能提供更多的源代码行吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM