I’m trying to fetch my data, but the results are empty!
First, I have a table, with data from one NSFetchedResultsController. Until here, my code is right, and also I know I have the data.
But then, I filter that NSFetchedResultsController, so I need another NSFetchedResultsController with the records without filter, I mean, all my records. So, I’m trying to fetch the data again, with another NSFetchedResultsController, using the same code, but the results is always empty!!!.
This is the functions that I’m using:
+(NSFetchedResultsController*)fetchedResultsControllerForEntity:(NSString*)entityName titleKey:(NSString*)titleKey sectionNameKeyPath:(NSString*)sectionNameKeyPath{
NSFetchRequest *request=[self fetchRequestForEntity:entityName titleKey:titleKey sectionNameKeyPath:sectionNameKeyPath];
return [[[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:[self managedContext]
sectionNameKeyPath:sectionNameKeyPath
cacheName:[NSString stringWithFormat:@"%@.%@.%@",entityName,sectionNameKeyPath,titleKey]]autorelease];
}
+(NSFetchRequest *) fetchRequestForEntity:(NSString*)entityName titleKey:(NSString*)titleKey sectionNameKeyPath:(NSString*)sectionNameKeyPath{
NSFetchRequest *request=[[[NSFetchRequest alloc]init]autorelease];
request.entity=[NSEntityDescription entityForName:entityName inManagedObjectContext:[self managedContext]];
NSSortDescriptor* titleSortDescriptor=titleKey?[[NSSortDescriptor alloc ]initWithKey:titleKey ascending:YES]:nil;
NSSortDescriptor* sectionSortDescriptor=sectionNameKeyPath?[[NSSortDescriptor alloc ]initWithKey:sectionNameKeyPath ascending:YES]:nil;
NSMutableArray * sortDescriptors=[[NSMutableArray alloc]init];
if(sectionNameKeyPath){
[sortDescriptors addObject:sectionSortDescriptor];
[sectionSortDescriptor release];
}
if(titleKey){
[sortDescriptors addObject:titleSortDescriptor];
[titleSortDescriptor release];
}
request.sortDescriptors=sortDescriptors;
[sortDescriptors release];
request.fetchBatchSize=20;
return request;
}
I don’t understand, why If I’m using the same code, my NSFetchResultsController is empty!!!
I tried to fetch data from another entity, but the result is also empty…
Why I’m missing?
Thanks
I already solved my problem. Just re-declare the SET method for the NSFetchedResultsController object:
I guess that’s why my object always was empty. Because the object