14.5. 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
calendars
array of the event store (for more information, refer to Recipe 14.1).Create an object of type
EKEvent
(for more information, refer to Recipe 14.2).Set the appropriate values for the event, such as its
startDate
andendDate
(for more information, refer to Recipe 14.2).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.Use the
recurrenceEndWithEndDate:
class method ofEKRecurrenceEnd
and pass theNSDate
you created in step 5 to create an object of typeEKRecurrenceEnd
.
Allocate and then instantiate an object of type
EKRecurrenceRule
using theinitRecurrenceWithFrequency:interval:end:
method ofEKRecurrenceRule
. Pass the recurrence end date that you created in step 6 to theend
parameter 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
recurringRule
property of theEKEvent
object that was created in step 3.Invoke the
saveEvent:span:error:
instance method with the event (created in step 3) as thesaveEvent
parameter and the valueEKSpanFutureEvents
for the ...
Get iOS 5 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.