Mac Developer Library

Developer

EventKit Framework Reference EKEventStore Class Reference

Options
Deployment Target:

On This Page
Language:

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. More...

Inheritance


Conforms To


Import Statement


import EventKit @import EventKit;

Availability


Available in OS X v10.8 and later.
  • Initializes access to the event store with support for the given entity type.

    Declaration

    Objective-C

    - (id)initWithAccessToEntityTypes:(EKEntityMask)entityTypes

    Parameters

    entityTypes

    The event or reminder entity mask.

    Return Value

    The event store.

    Import Statement

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.9.

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

    Declaration

    Swift

    func requestAccessToEntityType(_ entityType: EKEntityType, completion completion: EKEventStoreRequestAccessCompletionHandler!)

    Objective-C

    - (void)requestAccessToEntityType:(EKEntityType)entityType completion:(EKEventStoreRequestAccessCompletionHandler)completion

    Parameters

    entityType

    The event or reminder entity type.

    completion

    The block to call when the request completes.

    Discussion

    In iOS 6 and later, requesting access to an event store asynchronously prompts your users for permission to use their data. The user is only prompted the first time your app requests access to an entity type; any subsequent instantiations of EKEventStore uses existing permissions. When the user taps to grant or deny access, the completion handler will be called on an arbitrary queue. Your app is not blocked while the user decides to grant or deny permission.

    After users choose their permission level, the event store either calls the completion handler or broadcasts an EKEventStoreChangedNotification. The completion handler is called on iOS 6 and later, and the notification is broadcasted on iOS 5. Because users may deny access to the event store, your app should handle an empty data case.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.9 and later.

  • Returns the authorization status for the given entity type.

    Declaration

    Swift

    class func authorizationStatusForEntityType(_ entityType: EKEntityType) -> EKAuthorizationStatus

    Objective-C

    + (EKAuthorizationStatus)authorizationStatusForEntityType:(EKEntityType)entityType

    Parameters

    entityType

    The event or reminder entity type.

    Return Value

    The app’s authorization status of the given type.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.9 and later.

  • The unique identifier for the event store. (read-only)

    Declaration

    Swift

    var eventStoreIdentifier: String! { get }

    Objective-C

    @property(nonatomic, readonly) NSString *eventStoreIdentifier

    Discussion

    If the store is damaged, it is re-created and given a new identifier. If this value is different from a fetched value, you should take the appropriate action.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

  • The calendar that events are added to by default, as specified by user settings. (read-only)

    Declaration

    Swift

    var defaultCalendarForNewEvents: EKCalendar! { get }

    Objective-C

    @property(nonatomic, readonly) EKCalendar *defaultCalendarForNewEvents

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

  • The calendar that events are added to by default, as specified by user settings. (read-only)

    Declaration

    Swift

    func defaultCalendarForNewReminders() -> EKCalendar!

    Objective-C

    - (EKCalendar *)defaultCalendarForNewReminders

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

  • Returns the calendar with the specified identifier.

    Declaration

    Swift

    func calendarWithIdentifier(_ identifier: String!) -> EKCalendar!

    Objective-C

    - (EKCalendar *)calendarWithIdentifier:(NSString *)identifier

    Parameters

    identifier

    The calendar’s unique identifier.

    Return Value

    The calendar with the specified identifier.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func calendarsForEntityType(_ entityType: EKEntityType) -> [AnyObject]!

    Objective-C

    - (NSArray *)calendarsForEntityType:(EKEntityType)entityType

    Parameters

    entityType

    The calendar’s entity type.

    Return Value

    The calendar that supports the specified entity type.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

    See Also

    EKEntityType

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

    Declaration

    Swift

    func saveCalendar(_ calendar: EKCalendar!, commit commit: Bool, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)saveCalendar:(EKCalendar *)calendar commit:(BOOL)commit error:(NSError **)error

    Parameters

    calendar

    The calendar to be saved.

    commit

    YEStrue to save the calendar immediately; otherwise, the change is batched until the commit: method is invoked.

    error

    The error that occurred, if any; otherwise, nil.

    Return Value

    YEStrue if successful; otherwise, NOfalse.

    Discussion

    This method raises an exception if calendar belongs to another event store.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func removeCalendar(_ calendar: EKCalendar!, commit commit: Bool, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)removeCalendar:(EKCalendar *)calendar commit:(BOOL)commit error:(NSError **)error

    Parameters

    calendar

    The calendar to be removed.

    commit

    YEStrue to remove the calendar immediately; otherwise, the change is batched until the commit: method is invoked.

    error

    The error that occurred, if any; otherwise, nil.

    Return Value

    YEStrue if successful; otherwise, NOfalse.

    Discussion

    This method raises an exception if calendar belongs to another event store.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func saveEvent(_ event: EKEvent!, span span: EKSpan, commit commit: Bool, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)saveEvent:(EKEvent *)event span:(EKSpan)span commit:(BOOL)commit error:(NSError **)error

    Parameters

    event

    The event to be saved.

    span

    The span to use. Indicates whether the save affects future instances of the event in the case of a recurring event.

    commit

    To save the event immediately, pass YEStrue; otherwise, the change is batched until the commit: method is invoked.

    error

    The error that occurred, if any; otherwise, nil.

    Return Value

    If successful, YEStrue; otherwise, NOfalse. Also returns NOfalse if event does not need to be saved because it has not been modified.

    Discussion

    This method raises an exception if it is passed an event from another event store.

    When an event is saved, it is updated in the Calendar database. Any fields you did not modify are updated to reflect the most recent value in the database. If the event has been deleted from the database, it is re-created as a new event.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func removeEvent(_ event: EKEvent!, span span: EKSpan, commit commit: Bool, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)removeEvent:(EKEvent *)event span:(EKSpan)span commit:(BOOL)commit error:(NSError **)error

    Parameters

    event

    The event to remove.

    span

    The span to use. Indicates whether the remove affects future instances of the event in the case of a recurring event.

    commit

    YEStrue to remove the event immediately; otherwise, the change is batched until the commit: method is invoked.

    error

    The error that occurred, if any did. Otherwise, nil.

    Return Value

    If the event has successfully removed, YEStrue; otherwise, NOfalse. Also returns NOfalse if event cannot be removed because it is not in the event store.

    Discussion

    This method raises an exception if it is passed an event from another event store.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func saveReminder(_ reminder: EKReminder!, commit commit: Bool, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)saveReminder:(EKReminder *)reminder commit:(BOOL)commit error:(NSError **)error

    Parameters

    reminder

    The reminder to be saved.

    commit

    A Boolean value indicating whether to save the reminder immediately or to batch the changes; passing NOfalse will not commit changes to the event store until the commit: method is invoked.

    error

    The error that occurred, if any; otherwise, nil.

    Return Value

    If successful, YEStrue; otherwise, NOfalse.

    Discussion

    This method raises an exception if reminder belongs to another event store.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func removeReminder(_ reminder: EKReminder!, commit commit: Bool, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)removeReminder:(EKReminder *)reminder commit:(BOOL)commit error:(NSError **)error

    Parameters

    reminder

    The reminder to be removed.

    commit

    A Boolean value indicating whether to remove the reminder immediately or to batch the removals; passing NOfalse will not commit the removal from the event store until the commit: method is invoked.

    error

    The error that occurred, if any; otherwise, nil.

    Return Value

    If successful, YEStrue; otherwise, NOfalse.

    Discussion

    This method raises an exception if reminder belongs to another event store.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func calendarItemWithIdentifier(_ identifier: String!) -> EKCalendarItem!

    Objective-C

    - (EKCalendarItem *)calendarItemWithIdentifier:(NSString *)identifier

    Parameters

    identifier

    The calendar item’s unique identifier.

    Return Value

    The reminder or the first occurrence of an event with the specified identifier.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func calendarItemsWithExternalIdentifier(_ externalIdentifier: String!) -> [AnyObject]!

    Objective-C

    - (NSArray *)calendarItemsWithExternalIdentifier:(NSString *)externalIdentifier

    Parameters

    externalIdentifier

    The calendar item’s external identifier.

    Return Value

    An array of calendar items with the specified identifier.

    Discussion

    The external identifier can be obtained from the calendarItemExternalIdentifier property. There may be more than one matching calendar item due to reasons discussed in calendarItemExternalIdentifier.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

  • Returns an unordered array of source objects.

    Declaration

    Swift

    func sources() -> [AnyObject]!

    Objective-C

    - (NSArray *)sources

    Return Value

    An unordered array of EKSource objects.

    Discussion

    An EKSource object represents an account that contains calendars.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

  • Returns a source with the specified identifier.

    Declaration

    Swift

    func sourceWithIdentifier(_ identifier: String!) -> EKSource!

    Objective-C

    - (EKSource *)sourceWithIdentifier:(NSString *)identifier

    Parameters

    identifier

    The source’s unique identifier.

    Return Value

    The source with the specified identifier.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

  • Commits all unsaved changes to the event store.

    Declaration

    Swift

    func commit(_ error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)commit:(NSError **)error

    Parameters

    error

    A pointer to an NSError object. You do not need to create an NSError object. The commit operation aborts after the first failure if you pass NULL.

    Return Value

    If the commit operation succeeded, YEStrue; otherwise, NOfalse. Returns YEStrue even when there are no changes to commit.

    Discussion

    This method allows you to save batched changes to the event store. For example, if you pass NOfalse as the commit parameter to the saveCalendar:commit:error:, removeCalendar:commit:error:, saveEvent:span:commit:error:, or removeEvent:span:commit:error: methods, the changes are not saved until this method is invoked. Likewise, if you pass YEStrue as the commit parameter to the aforementioned methods, there is no need to call this method.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

  • Returns the event store to its saved state.

    Declaration

    Swift

    func reset()

    Objective-C

    - (void)reset

    Discussion

    This method updates all the properties of all the objects with their corresponding values in the event store. Any local changes that were not saved before invoking this method will be lost. All objects that were created or retrieved using this store are disassociated from it and should be considered invalid.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

    See Also

    reset

  • Pulls new data from remote sources if necessary.

    Declaration

    Swift

    func refreshSourcesIfNecessary()

    Objective-C

    - (void)refreshSourcesIfNecessary

    Discussion

    Use this method to pull new data from remote sources if the local data is out of date.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

Data Types

  • The signature for a block object used for operating on events with the requestAccessToEntityType:completion: method.

    Declaration

    Swift

    typealias EKEventStoreRequestAccessCompletionHandler = (Bool, NSError!) -> Void

    Objective-C

    typedef void (^EKEventStoreRequestAccessCompletionHandler)(BOOL granted, NSError *error);

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.9 and later.

  • The signature for a block object used for operating on events with the enumerateEventsMatchingPredicate:usingBlock: method.

    Declaration

    Swift

    typealias EKEventSearchCallback = (EKEvent!, UnsafeMutablePointer<ObjCBool>) -> Void

    Objective-C

    typedef void (^EKEventSearchCallback)(EKEvent *event, BOOL *stop);

    Discussion

    The event argument is the event to operate on. You can set the value of the stop argument to YEStrue to tell the enumerateEventsMatchingPredicate:usingBlock: method to stop processing events when this block returns.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    struct EKSpan { init(_ value: UInt32) var value: UInt32 }

    Objective-C

    typedef enum { EKSpanThisEvent, EKSpanFutureEvents } EKSpan;

    Constants

    • EKSpanThisEvent

      EKSpanThisEvent

      Modifications to this event instance should affect only this instance.

      Available in OS X v10.8 and later.

    • EKSpanFutureEvents

      EKSpanFutureEvents

      Modifications to this event instance should also affect future instances of this event.

      Available in OS X v10.8 and later.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.

  • Indicates the current authorization status for a specific entity type.

    Declaration

    Swift

    enum EKAuthorizationStatus : Int { case NotDetermined case Restricted case Denied case Authorized }

    Objective-C

    typedef enum { EKAuthorizationStatusNotDetermined = 0, EKAuthorizationStatusRestricted, EKAuthorizationStatusDenied, EKAuthorizationStatusAuthorized } EKAuthorizationStatus;

    Constants

    • NotDetermined

      EKAuthorizationStatusNotDetermined

      The user has not yet made a choice regarding whether the app may access the service.

      Available in OS X v10.9 and later.

    • Restricted

      EKAuthorizationStatusRestricted

      The app is not authorized to access the service. The user cannot change this app’s authorization status, possibly due to active restrictions such as parental controls being in place.

      Available in OS X v10.9 and later.

    • Denied

      EKAuthorizationStatusDenied

      The user explicitly denied access to the service for the app.

      Available in OS X v10.9 and later.

    • Authorized

      EKAuthorizationStatusAuthorized

      The app is authorized to access the service.

      Available in OS X v10.9 and later.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.9 and later.

  • 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 YEStrue, you do not need to refetch the event.

    Import Statement

    import EventKit

    Availability

    Available in OS X v10.8 and later.