3

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

3 Answers3

2

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.

Jim Conroy
  • 341
  • 4
  • 8
1

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:

  1. All completed reminders are listed below the open (incomplete) reminders

  2. the open reminders are sorted by the alarm date (alarm.absoluteDate)

  3. 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
Kabeer
  • 51
  • 2
0

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];
mhunter007
  • 114
  • 3