Hi i have a function which fetches data from coreData. Here is the method
- (NSArray *)fetchRequestWithEntity:(NSEntityDescription *)entity
predicate:(NSPredicate *)predicate
sort:(NSArray *)sortDescriptors
range:(NSRange)range {
NSError *error = nil;
NSFetchRequest *request = [NSFetchRequest new];
[request setEntity:entity];
if (predicate != nil) {
request.predicate = predicate;
}
if (sortDescriptors) {
request.sortDescriptors = sortDescriptors;
}
if (range.length > 0) {
request.fetchLimit = range.length;
}
if (range.location > 0) {
request.fetchOffset = range.location;
}
request.fetchBatchSize = 15;
NSArray *array = [self executeFetchRequest:request error:&error];
if (!error) {
return array;
}
else {
NSLOG("Error");
return nil;
}
}
The program is crashing at this line.
NSArray *array = [self executeFetchRequest:request error:&error];
I checked the value of all the parameters of the method and everything seems to be fine. Does this have anything to do with the "sortDescriptors" parameter of the method?
This is how I am getting NSSortDescriptor
+ (NSArray *)sortDescriptors {
return @[[[NSSortDescriptor alloc] initWithKey:EIKNewsHeadlineAttributeStoryDateTime ascending:NO]];
}
I checked the parameters of the method ,i have a valid entity and sortDescriptor. Value of predicate is nil and my range is (location=0 and length=0). What is causing the problem?