0

나는 EKReminder 개체 배열을 가지고 있으며 기한까지 정렬하고 싶습니다.듀엣 날짜를 기반으로 EKReminder를 정렬하십시오

이 이런 일을 쉽게 처음 보인다

NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dueDate" ascending:YES]; 

[remindersArray sortUsingDescriptors:@[dateDescriptor]]; 

EKReminder의 기한이 NSDateComponents 객체가 아닌 NSDate입니다 그러나.

아이디어가 있으십니까?

+0

'dateFromComponents :'를 사용하여 날짜를 얻고 날짜를 정렬 하시겠습니까? – matt

+0

감사합니다.하지만 해당 날짜에 어떻게 정렬합니까? –

+0

날짜는 단지 몇 초이므로 자연히 정렬 할 수 있습니다. – matt

답변

0

그래서, 몇 가지 조사 후 나는 비교적 쉽게 그것을 해결하기 위해 관리 :

[allReminders sortUsingComparator:^NSComparisonResult(id obj1,id obj2){ 
     EKReminder *reminder1 = obj1; 
     EKReminder *reminder2 = obj2; 

     NSDate *date1 = [reminder1.dueDateComponents date]; 
     NSDate *date2 = [reminder2.dueDateComponents date]; 
     return [date1 compare:date2]; 
    }]; 

희망이 누군가를하는 데 도움이!