How do I get all entries from an NSFetchedResultsController / NSManagedObjectContext?

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

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];
Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » How do I get all entries from an NSFetchedResultsController / NSManagedObjectContext?

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录