我是一种使用密钥整理NSManagedObjects的方法。该方法如下所示:
- (NSMutableArray *)sortArrayDateWise:(NSMutableArray *)arr_msg withKey:(NSString *)str_key isAscending:(BOOL)isAscending andDateFormat:(NSString *)str_dateFormat {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:str_dateFormat];
NSComparator compareDates = ^(id string1, id string2) {
NSDate *date1 = [formatter dateFromString:string1];
NSDate *date2 = [formatter dateFromString:string2];
return [date1 compare:date2];
};
NSSortDescriptor *sortDesc = [[NSSortDescriptor alloc] initWithKey:str_key ascending:isAscending comparator:compareDates];
[arr_msg sortUsingDescriptors:[NSArray arrayWithObjects:sortDesc, nil]];
return arr_msg;
}
大部分时间它都能很好地工作,但有时会出现像
这样的错误EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000010
如何解决这个问题?