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

综合技术 2017-12-31

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!

责编内容by:Hello, buddy! (源链)。感谢您的支持!


Is there a way to take a picture on iOS7 so as not... I am wondering if this is actually possible to do. I know I can flip an UIImageView, but the camera on iOS 7 shows the picture flipped horizontally be...
iOS将文件切片储存并上传仿断点续传机制... 简介: 在开发中,一般在视频类的app或者与硬件交互的app中会有将数据文件上传到云端,少数社交app上传图片也比较多。下面讲的是将数据文件(txt类型)切片储存到本地并逐片上传到云端模仿断点续传的机制,但事实上,这个操作并不是真正的断点续传。 google了一下,关于切分的文章也蛮多,但是...
GCD 深入理解:第二部分 本文翻译自… 原作者:Derek Selander 译者:Riven、 @nixzhu 欢迎来到GCD深入理解系列教程的第二部分(也是最后一部分)。 在本系列的第一部分中,你已经学...
如何全面高效高质量进行 iOS技术开发 目前市场上iOS初级开发者人满为患,在这个狭小的世界里面大家都不知道生存的空间在哪里~其实在往上还有更广阔的天地,中级高级的开发者还是非常稀缺的,这里有让你傲视群伦的技术,让你再次问鼎iOS开发者辉煌之路。 H264编码 主讲老师CC老师 主题大纲扎克伯格说“视频是未来facebo...
App Store Upload Failures I’ve been running into failures to connect to iTunes Connect through Application Loader. Others corroborate similar problems uploading through Xcode ...