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:
Create an instance of
EKEventStore.Find a modifiable calendar inside the event store, as we saw in Recipe 19.3.
Create an object of type
EKEvent(for more information, refer to Recipe 19.3).Set the appropriate values for the event, such as its
startDateandendDate(for more information, refer to Recipe 19.3).Instantiate an object of type
NSDatethat contains the exact date when the recurrence of this event ends. In this example, this date is one year from today’s date.Use the
recurrenceEndWithEndDate:class method ofEKRecurrenceEndand pass theNSDateyou created in step 5 to create an object of typeEKRecurrenceEnd.
Allocate and then instantiate an object of type
EKRecurrenceRuleusing theinitRecurrenceWithFrequency:interval:end:method ofEKRecurrenceRule. Pass the recurrence end date that you created in step 6 to theendparameter of this method. For more information about this method, please refer to this recipe’s Discussion.Assign the recurring event that you created in step 7 to the
recurringRuleproperty of theEKEventobject that was created in step 3.Invoke the
saveEvent:span:error:instance method with the event (created in step 3) as thesaveEventparameter and the valueEKSpanFutureEventsfor thespanparameter. This will create our recurring ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access