edc1591
edc1591

Reputation: 10182

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. 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. 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. 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.

Upvotes: 0

Views: 1005

Answers (1)

tt.Kilew
tt.Kilew

Reputation: 6084

1. I think that this is can be possible if you're ignoring error's on

[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

request.includesPendingChanges = NO;

If there's no correct answer :) Can you provide a bit more lines of source code?

Upvotes: 1

Related Questions