19.6. Adding Recurring Events to Calendars

Problem

You want to add a recurring event to a calendar.

Solution

In this example, we are creating an event that occurs on the same day, every month, for an entire year. The steps are as follows:

  1. Create an instance of EKEventStore.

  2. Find a modifiable calendar inside the event store, as we saw in Recipe 19.3.

  3. Create an object of type EKEvent (for more information, refer to Recipe 19.3).

  4. Set the appropriate values for the event, such as its startDate and endDate (for more information, refer to Recipe 19.3).

  5. Instantiate an object of type NSDate that contains the exact date when the recurrence of this event ends. In this example, this date is one year from today’s date.

  6. Use the recurrenceEndWithEndDate: class method of EKRecurrenceEnd and pass the NSDate you created in step 5 to create an object of type EKRecurrenceEnd.

  1. Allocate and then instantiate an object of type EKRecurrenceRule using the initRecurrenceWithFrequency:interval:end: method of EKRecurrenceRule. Pass the recurrence end date that you created in step 6 to the end parameter of this method. For more information about this method, please refer to this recipe’s Discussion.

  2. Assign the recurring event that you created in step 7 to the recurringRule property of the EKEvent object that was created in step 3.

  3. Invoke the saveEvent:span:error: instance method with the event (created in step 3) as the saveEvent parameter and the value EKSpanFutureEvents for the span parameter. This will create our recurring ...

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.