How to get all entries of a NSFetchedResultsController/NSManagedObjectContext?
Asked Answered
F

2

15

I have a nice working iphone app that works with core data. I use a NSFetchedResultsController/NSManagedObjectContext as described in various tutorials.

Now I want to extends my app and add some more features. The problem I need to build up an array with objects that have informations from my data.

I somehow need to get a list of all data I have in my context.

I thought I could make an approach similar to the way I get the data for the UITableView.

id <NSFetchedResultsSectionInfo> sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section];

This one fails, because I do have actually multiple sections. Now I could go through all sections and make my own IndexPath to access my data with :

MyData *info = [_fetchedResultsController objectAtIndexPath:indexPath];

But I think there is another way I just have not found yet and I hope someone can help me out here.

Thanks a lot.

Fibrinogen answered 9/10, 2010 at 22:54 Comment(0)
M
42

are you just looking for a method to get all objects from you NSFetchedResultsController? If so, use this.

NSArray *fetchedData = [_fetchedResultsController fetchedObjects];

if you have more than 1 entity build a fetchrequest for each entity. Something like this should give you all your objects.

NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:self.entityName inManagedObjectContext:self.managedObjectContext];
[request setEntity:entity];
NSError *error;
NSArray *results = [self.managedObjectContext executeFetchRequest:request error:&error];
Manner answered 9/10, 2010 at 23:8 Comment(0)
D
1

If you wanted to get all of the objects for a particular section you could do this:

NSArray *sectionObjects = [_fetchedResultsController.sections[section_number] objects];
Delia answered 25/7, 2014 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.