19.7. Retrieving the Attendees of an Event

Problem

You want to retrieve the list of attendees for a specific event.

Solution

Use the attendees property of an instance of EKEvent. This property is of type NSArray and includes objects of type EKParticipant.

The example code that follows will retrieve all the events that happen today (whatever the day may be) and print out useful event information, including the attendees of that event, to the console window:

- (void) enumerateTodayEventsInStore:(EKEventStore *)paramStore
                            calendar:(EKCalendar *)paramCalendar{

    /* Construct the starting date for today */
    NSDate *startDate = [NSDate date];

    /* The end date will be 1 day from now */
    NSTimeInterval NSOneDay = 1 * 24 * 60 * 60;
    NSDate *endDate = [startDate dateByAddingTimeInterval:NSOneDay];

    /* Create the predicate that we can later pass to
     the event store in order to fetch the events */
    NSPredicate *searchPredicate =
    [paramStore predicateForEventsWithStartDate:startDate
                                        endDate:endDate
                                      calendars:@[paramCalendar]];

    /* Make sure we succeeded in creating the predicate */
    if (searchPredicate == nil){
        NSLog(@"Could not create the search predicate.");
        return;
    }

    /* Fetch all the events that fall between the
     starting and the ending dates */
    NSArray *events = [paramStore eventsMatchingPredicate:searchPredicate];

    /* Array of NSString equivalents of the values
     in the EKParticipantRole enumeration */
    NSArray *attendeeRole = @[
                              @"Unknown",
                              @"Required",
                              @"Optional",
                              @"Chair",
                              @"Non Participant",
                              ];

    /* Array ...

Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.