Does CoreData always support returnObjectsasFaults?

In the following code, I explicitly set returnObjectsasFaults to false. Then, CORRECTLY after the request, I check if the objects are to blame. NSAssert error.

Perhaps this is because the object is imageBlob. Maybe I missed something? I just want to make sure.

This is a minor issue. If I get rid of nsassert, then my programs will work anyway. It still sucks.

+(NSFetchRequest * )fetchRequestInContext:(NSString*) entityName:(NSPredicate *) predicate:(NSString*) sortKey:(BOOL) sortAscending { //NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[BGMDCRManagedObjectContextThreadHandler managedObjectContext]]; [request setEntity:entity]; if(predicate != nil) { [request setPredicate:predicate]; } if(sortKey != nil) { NSMutableArray * sortDescriptorArray =[self getMoreSearchDescriptorsForEntity:entityName]; [request setSortDescriptors:sortDescriptorArray]; } //request.fetchLimit = 200; //can be overridden somewhere else request.returnsObjectsAsFaults = false; if (entityName == BusinessString) { request.relationshipKeyPathsForPrefetching = arrayRelationship; } //[request setIncludesSubentities:<#(BOOL)#> return request; } +(NSArray *) searchObjectsInContextEntityName:(NSString*) entityName Predicate:(NSPredicate *) predicate SortKEy:(NSString*) sortKey Booelan:(BOOL) sortAscending { NSManagedObjectContext * moc =[BGMDCRManagedObjectContextThreadHandler managedObjectContext]; NSFetchRequest *request = [self fetchRequestInContext:entityName:predicate:sortKey:sortAscending]; NSError *error; if (entityName==BusinessString) { error=nil; //Some code for breakpoint } NSArray *fetchedObjects = [moc executeFetchRequest:request error:&error]; for (NSManagedObject * mo in fetchedObjects) { NSAssert(!mo.isFault, @"For some reason mo is fault"); } return fetchedObjects; } 
+4
objective-c core-data
source share
1 answer

I encountered the same problem when working with a child of NSManagedObjectContext. I create it as follows

 NSManagedObjectContext *workerMOC = nil; workerMOC = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; workerMOC.parentContext = self.moc; // this is my main NSManagedObjectContext 

Now if I do this:

 [workerMOC performBlock:^{ NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Company"]; [fetchRequest setReturnsObjectsAsFaults:NO]; NSArray *allCompanies = [workerMOC executeFetchRequest:fetchRequest error:nil]; }]; 

I get errors in all companies. Which, of course, just for clarification, does not happen if I execute a fetch request on self.moc.

However, I get relevant preliminary results if I use the following approach:

 [workerMOC performBlock:^{ NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease]; fetchRequest.entity = [NSEntityDescription entityForName:@"Company" inManagedObjectContext:workerMOC]; [fetchRequest setReturnsObjectsAsFaults:NO]; NSArray *allCompanies = [workerMOC.persistentStoreCoordinator executeRequest:fetchRequest withContext:workerMOC error:nil]; }]; 

So, it seems that fetching at NSManagedObjectContexts, directly related to NSPsistentStoreCoordinator, works just fine. But in the case of child NSManagedObjectContexts that are not directly bound to the repository, but rather to the parent context, do not behave as expected. I could not find anything related to this issue in Apple docs, but still, I don't think this is a mistake.

+7
source share

All Articles