O'Reilly logo

iOS 7 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required