当日のすべてのイベントを取得するには、次の方法があります。
- (NSArray *)fetchEventsForToday {
NSDate *startDate = [NSDate date];
// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];
// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray];
// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
NSLog(@"array: %@", events);
return events;
}
NSLog を確認すると、配列に次のオブジェクトが表示されます。
2011-06-29 19:24:01.383 SimpleEKDemo[2945:207] array: (
"EKEvent <0x5118cd0> { EKEvent <0x5118cd0> {
title = Test;
calendar = EKCalendar <0x5105d60> {
title = Calendar;
type = Local;
account = (null);
allowsModify = YES;
color = 0.443137 0.101961 0.462745 1.000000
};
alarms = (null);
URL = (null);
lastModified = 2011-06-29 23:51:51 +0000
};
location = (null);
startDate = 2011-06-30 00:30:00 +0000;
endDate = 2011-06-30 01:30:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
}",
"EKEvent <0x5118380> {EKEvent <0x5118380> {
title = Prueba;
calendar = EKCalendar <0x5105d60> {
title = Calendar;
type = Local;
account = (null);
allowsModify = YES;
color = 0.443137 0.101961 0.462745 1.000000
};
alarms = (null);
URL = (null);
lastModified = 2011-06-29 23:51:58 +0000};
location = (null);
startDate = 2011-06-30 00:30:00 +0000;
endDate = 2011-06-30 01:30:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
}",
"EKEvent <0x5117f70> {EKEvent <0x5117f70> {
title = Numero;
calendar = EKCalendar <0x5105d60> {
title = Calendar;
type = Local;
account = (null);
allowsModify = YES;
color = 0.443137 0.101961 0.462745 1.000000
};
alarms = (null);
URL = (null);
lastModified = 2011-06-29 23:53:54 +0000};
location = (null);
startDate = 2011-06-30 00:30:00 +0000;
endDate = 2011-06-30 01:30:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
}"
ご覧のとおり、「test」、「Prueba」、「Numero」という 3 つのオブジェクトがあり、このタイトルと開始日と終了日はすべて必要な情報ですが、取得方法がわかりません。誰か助けてくれませんか?