Chapter 20. Calendar
The user’s calendar information constitutes a database of calendar events. This database also includes reminders. The user can interact with the calendar events through the Calendar app, and with the reminders through the Reminders app. Your code can access the database through the EventKit framework. You’ll need to import EventKit. An interface for allowing the user to interact with the calendar from within your app is also provided, through the EventKit UI framework. You’ll need to import EventKitUI.
The database is accessed as an instance of the EKEventStore class. This instance is expensive to obtain but lightweight to maintain, so your usual strategy will be to instantiate and retain one EKEventStore instance. There is no harm in initializing a property or global as an EKEventStore instance and keeping that reference for the rest of the app’s lifetime:
let database = EKEventStore()
In the examples in this chapter, my EKEventStore instance is called self.database throughout.
Access to the database requires user authorization. You’ll use the EKEventStore class for this. Although there is one database, access to calendar events and access to reminders are considered two separate forms of access and require separate authorizations. To learn what the current authorization status is, call the class method authorizationStatus(for:) with an EKEntityType, either .event (for access to calendar events) or .reminder (for access to reminders). To ask the system to ...
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