is there a way to sort the Calendar or Reminders? I haven't found a sortIndex properties or something like that... How the reminder app do sort there items?
Best regards
is there a way to sort the Calendar or Reminders? I haven't found a sortIndex properties or something like that... How the reminder app do sort there items?
Best regards
Currently in iOS 6 SDK there is no public access to the sort index used by the Reminders app. You will need to sort using some other method within your app.
Here is a category of EKReminder, containing a method to compare 2 reminders (EKReminder instances). Then I use the NSArray method “sortUsingSelector” as follows:
[myReminders sortUsingSelector:@selector(compare:)];
The sorting criteria is follows:
All completed reminders are listed below the open (incomplete) reminders
the open reminders are sorted by the alarm date (alarm.absoluteDate)
the completed reminders are sorted by the completionDate
Hope this helps!
Use with:
#import "EKReminder+Sort.h"
EKReminder+Sort.h:
@implementation EKReminder (Sort)
-(NSComparisonResult)compare:(EKReminder*)reminder {
NSComparisonResult result = NSOrderedSame;
if(self.completed) {
if(reminder.completed) {
result = [reminder.completionDate compare:self.completionDate];
} else {
result = NSOrderedDescending;
}
} else {
if(reminder.completed) {
//do nothing
result = NSOrderedSame;
} else {
NSDate *date1 = [self.alarms.firstObject absoluteDate];
NSDate *date2 = [reminder.alarms.firstObject absoluteDate];
if(date1) {
if(date2) {
result = [date1 compare:date2];
} else {
result = NSOrderedDescending;
}
} else {
//do nothing
result = NSOrderedSame;
}
}
}
return result;
}
@end
I used this to sort EKReminders by priority
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"priority" ascending:YES] ;
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray = [unsortedArray sortedArrayUsingDescriptors:sortDescriptors];