Article

Creating Events and Reminders

Create and modify events and reminders in a user's database.

Overview

Once you have permission to access a user's Calendar and Reminder data, you can create, display, and edit events and reminders.

Create Events

Create a new event with the init(eventStore:) method of the EKEvent class.

You can edit the details of a new event or an event you previously fetched from the Calendar database by setting the event’s corresponding properties. Some of the details you can edit include:

  • The event’s title with the title property.

  • The event’s start and end dates with the startDate and endDate properties.

  • The calendar with which the event is associated with the calendar property.

  • The alarms associated with the event with the alarms property (see "Setting an Alarm" for more details).

  • The event’s recurrence rule, if it is a repeating event, with the recurrenceRules property (see "Creating a Recurring Event" for more details).

Save and Delete Events

Save your changes to the Calendar database with the EKEventStore method save(_:span:commit:). If you want to remove an event from the Calendar database, use the EKEventStore method remove(_:span:commit:). Whether you are saving or removing an event, implementing the respective method automatically syncs your changes with the calendar the event belongs to (CalDAV, Exchange, and so on).

If you are saving a recurring event, your changes can apply to all future occurrences of the event by specifying EKSpan.futureEvents for the span parameter of the save(_:span:commit:) method. Likewise, you can remove all future occurrences of an event by specifying EKSpan.futureEvents for the span parameter of the remove(_:span:commit:) method.

Create Reminders

Reminders are tasks that may be tied to a specific time or location. They are similar to calendar events, but can be marked complete and may not necessarily span an exact period of time.

Because EKReminder inherits from EKCalendarItem, you can perform the same methods on a reminder as you would on an event, such as adding an alarm with addAlarm(_:) or setting a recurrence rule with addRecurrenceRule(_:).

You can create reminders using the init(eventStore:) class method. The title and calendar properties are required. The calendar for a reminder is the list with which it is grouped.

Like events, reminders can trigger time-based or location-based alarms to alert the user of a certain task. Read "Setting an Alarm" for more information on how to attach alarms to calendar items.

Save and Delete Reminders

To save a reminder to the Calendar database, call the save(_:commit:) method. To remove an event, call the remove(_:commit:) method. The title and calendars properties must explicitly be set before you save the reminder.

Edit Reminders

To associate a start date or due date with a reminder, use the startDateComponents and dueDateComponents properties. To complete a reminder, set the completed property to YES, which automatically sets completionDate to the current date.

See Also

Events and Reminders

Retrieving Events and Reminders

Fetch events and reminders from the Calendar database.

Updating with Notifications

Register to be notified about changes and keep your app up to date.

class EKEvent

A class that represents an event added to a calendar.

class EKReminder

A class that represents a reminder added to a calendar.