Class

EKEventStore

An instance of the EKEventStore class represents the Calendar database. It is an application’s point of contact for accessing calendar and reminder data.

Overview

In iOS, you must request access to an entity type after the event store is initialized with requestAccess(to:completion:) for data to return.

In macOS, use initWithAccessToEntityTypes: instead of the default init method. Acceptable entity types are event for events and reminder for reminders.

Create a predicate, or a search query for events, with the predicateForEvents(withStart:end:calendars:) method.

Fetch and process events that match a given predicate with the events(matching:) and enumerateEvents(matching:using:) methods.

Save and delete events from the event store with the save(_:span:commit:) and remove(_:span:commit:) methods.

Use similar methods to access and manipulate reminders. Reminders are not available in Event Kit before iOS 6.

Symbols

Accessing the Event Store

func requestAccess(to: EKEntityType, completion: EKEventStoreRequestAccessCompletionHandler)

Prompts the user to grant or deny access to event or reminder data.

class func authorizationStatus(for: EKEntityType)

Returns the authorization status for the given entity type.

var eventStoreIdentifier: String

The unique identifier for the event store.

Accessing Calendars

var calendars: [EKCalendar]

The calendars associated with the event store, as an array of EKCalendar objects.

Deprecated
var defaultCalendarForNewEvents: EKCalendar

The calendar that events are added to by default, as specified by user settings.

func defaultCalendarForNewReminders()

The calendar that events are added to by default, as specified by user settings.

func calendar(withIdentifier: String)

Returns the calendar with the specified identifier.

func calendars(for: EKEntityType)

Returns calendars that support a given entity type, such as reminders or events.

Saving and Removing Calendars

func saveCalendar(EKCalendar, commit: Bool)

Saves a calendar to the event store by either committing or batching the changes.

func removeCalendar(EKCalendar, commit: Bool)

Removes a calendar from the event store by either batching or committing the changes.

Accessing Events

func event(withIdentifier: String)

Returns the first occurrence of an event with a given identifier.

func events(matching: NSPredicate)

Returns all events that match a given predicate.

func enumerateEvents(matching: NSPredicate, using: EKEventSearchCallback)

Finds all events that match a given predicate and calls a given callback for each event found.

func predicateForEvents(withStart: Date, end: Date, calendars: [EKCalendar]?)

Creates and returns a predicate for finding events in the event store that fall within a given date range.

Saving and Removing Events

func save(EKEvent, span: EKSpan)

Saves changes to an event permanently.

func save(EKEvent, span: EKSpan, commit: Bool)

Saves an event or recurring events to the event store by either batching or committing the changes.

func remove(EKEvent, span: EKSpan)

Removes an event from the event store.

func remove(EKEvent, span: EKSpan, commit: Bool)

Removes an event or recurring events from the event store by either batching or committing the changes.

Accessing Reminders

func predicateForReminders(in: [EKCalendar]?)

Fetches all reminders in a set of calendars.

func predicateForIncompleteReminders(withDueDateStarting: Date?, ending: Date?, calendars: [EKCalendar]?)

Fetches incomplete reminders in a set of calendars within an optional range.

func predicateForCompletedReminders(withCompletionDateStarting: Date?, ending: Date?, calendars: [EKCalendar]?)

Fetches completed reminders in a set of calendars within an optional range.

func cancelFetchRequest(Any)

Cancels the request to fetch reminders.

Saving and Removing Reminders

func save(EKReminder, commit: Bool)

Saves changes to a reminder by either committing or batching the changes.

func remove(EKReminder, commit: Bool)

Removes a reminder from the event store by either committing or batching the changes.

Accessing Events or Reminders

func calendarItem(withIdentifier: String)

Returns either the event’s first occurrence or the reminder with the specified identifier.

func calendarItems(withExternalIdentifier: String)

Returns either the event’s first occurrences or the reminders with the specified external identifier.

Accessing Sources

var sources: [EKSource]

Returns an unordered array of source objects.

func source(withIdentifier: String)

Returns a source with the specified identifier.

Saving and Restoring State

func commit()

Commits all unsaved changes to the event store.

func reset()

Returns the event store to its saved state.

func refreshSourcesIfNecessary()

Pulls new data from remote sources if necessary.

Constants

EKSpan

Indicates whether modifications should apply to a single event or all future events of a recurring event.

EKAuthorizationStatus

Indicates the current authorization status for a specific entity type.

EKEventStoreRequestAccessCompletionHandler

The signature for a block object used for operating on events with the requestAccess(to:completion:) method.

EKEventSearchCallback

The signature for a block object used for operating on events with the enumerateEvents(matching:using:) method.

Notifications

static let EKEventStoreChanged: NSNotification.Name

Posted whenever changes are made to the Calendar database, including adding, removing, and changing events or reminders. Individual changes are not described. When you receive this notification, you should refetch all EKEvent and EKReminder objects you have accessed, as they are considered stale. If you are actively editing an event and do not wish to refetch it unless it is absolutely necessary to do so, you can call the refresh method on it. If the method returns true, you do not need to refetch the event.

Relationships

Inherits From

Conforms To