Skill v1.0.2
LLM-judged scan100/1001 files
version: "1.0.2" name: eventkit description: "Create, read, and manage calendar events and reminders using EventKit and EventKitUI. Use when adding events to the user's calendar, creating reminders, setting recurrence rules, requesting calendar or reminders access, presenting event editors, choosing calendars, handling alarms, observing calendar changes, or working with EKEventStore, EKEvent, EKReminder, EKCalendar, EKRecurrenceRule, EKEventEditViewController, EKCalendarChooser, or EventKitUI views."
EventKit
Create, read, and manage calendar events and reminders. Covers authorization, event and reminder CRUD, recurrence rules, alarms, and EventKitUI editors. Targets Swift 6.3 / iOS 26+.
Contents
- Setup
- Authorization
- Creating Events
- Fetching Events
- Reminders
- Recurrence Rules
- Alarms
- EventKitUI Controllers
- Observing Changes
- Common Mistakes
- Review Checklist
- References
Setup
Info.plist Keys
Add the required usage description strings based on what access level you need:
| Key | Access Level | |
|---|---|---|
NSCalendarsFullAccessUsageDescription | Read + write events | |
NSCalendarsWriteOnlyAccessUsageDescription | Write-only events (iOS 17+) | |
NSRemindersFullAccessUsageDescription | Read + write reminders |
For apps also targeting iOS 16 or earlier, also include the legacyNSCalendarsUsageDescription/NSRemindersUsageDescriptionkeys.
Event Store
Create a single EKEventStore instance and reuse it. Do not mix objects from different event stores.
import EventKitlet eventStore = EKEventStore()
Authorization
iOS 17+ introduced granular access levels. Use the modern async methods.
Full Access to Events
func requestCalendarAccess() async throws -> Bool {let granted = try await eventStore.requestFullAccessToEvents()return granted}
Write-Only Access to Events
Use when your app only creates events (e.g., saving a booking) and does not need to read existing events.
func requestWriteAccess() async throws -> Bool {let granted = try await eventStore.requestWriteOnlyAccessToEvents()return granted}
Full Access to Reminders
func requestRemindersAccess() async throws -> Bool {let granted = try await eventStore.requestFullAccessToReminders()return granted}
Checking Authorization Status
let status = EKEventStore.authorizationStatus(for: .event)switch status {case .notDetermined:// Request accessbreakcase .fullAccess:// Read and write allowedbreakcase .writeOnly:// Write-only access granted (iOS 17+)breakcase .restricted:// Parental controls or MDM restrictionbreakcase .denied:// User denied -- direct to Settingsbreak@unknown default:break}
Creating Events
func createEvent(title: String,startDate: Date,endDate: Date,calendar: EKCalendar? = nil) throws {let event = EKEvent(eventStore: eventStore)event.title = titleevent.startDate = startDateevent.endDate = endDateevent.calendar = calendar ?? eventStore.defaultCalendarForNewEventstry eventStore.save(event, span: .thisEvent)}
Setting a Specific Calendar
// List writable calendarslet calendars = eventStore.calendars(for: .event).filter { $0.allowsContentModifications }// Use the first writable calendar, or the defaultlet targetCalendar = calendars.first ?? eventStore.defaultCalendarForNewEventsevent.calendar = targetCalendar
Adding Structured Location
import CoreLocationlet location = EKStructuredLocation(title: "Apple Park")location.geoLocation = CLLocation(latitude: 37.3349, longitude: -122.0090)event.structuredLocation = location
Fetching Events
Use a date-range predicate to query events. The events(matching:) method returns occurrences of recurring events expanded within the range.
func fetchEvents(from start: Date, to end: Date) -> [EKEvent] {let predicate = eventStore.predicateForEvents(withStart: start,end: end,calendars: nil // nil = all calendars)return eventStore.events(matching: predicate).sorted { $0.startDate < $1.startDate }}
Fetching a Single Event by Identifier
if let event = eventStore.event(withIdentifier: savedEventID) {print(event.title ?? "No title")}
Reminders
Creating a Reminder
func createReminder(title: String, dueDate: Date) throws {let reminder = EKReminder(eventStore: eventStore)reminder.title = titlereminder.calendar = eventStore.defaultCalendarForNewReminders()let dueDateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute],from: dueDate)reminder.dueDateComponents = dueDateComponentstry eventStore.save(reminder, commit: true)}
Fetching Reminders
Reminder fetches are asynchronous and return through a completion handler.
func fetchIncompleteReminders() async -> [EKReminder] {let predicate = eventStore.predicateForIncompleteReminders(withDueDateStarting: nil,ending: nil,calendars: nil)return await withCheckedContinuation { continuation ineventStore.fetchReminders(matching: predicate) { reminders incontinuation.resume(returning: reminders ?? [])}}}
Completing a Reminder
func completeReminder(_ reminder: EKReminder) throws {reminder.isCompleted = truetry eventStore.save(reminder, commit: true)}
Recurrence Rules
Use EKRecurrenceRule to create repeating events or reminders.
Simple Recurrence
// Every week, indefinitelylet weeklyRule = EKRecurrenceRule(recurrenceWith: .weekly,interval: 1,end: nil)event.addRecurrenceRule(weeklyRule)// Every 2 weeks, ending after 10 occurrenceslet biweeklyRule = EKRecurrenceRule(recurrenceWith: .weekly,interval: 2,end: EKRecurrenceEnd(occurrenceCount: 10))// Monthly, ending on a specific datelet monthlyRule = EKRecurrenceRule(recurrenceWith: .monthly,interval: 1,end: EKRecurrenceEnd(end: endDate))
Complex Recurrence
// Every Monday and Wednesdaylet days = [EKRecurrenceDayOfWeek(.monday),EKRecurrenceDayOfWeek(.wednesday)]let complexRule = EKRecurrenceRule(recurrenceWith: .weekly,interval: 1,daysOfTheWeek: days,daysOfTheMonth: nil,monthsOfTheYear: nil,weeksOfTheYear: nil,daysOfTheYear: nil,setPositions: nil,end: nil)event.addRecurrenceRule(complexRule)
Editing Recurring Events
When saving changes to a recurring event, specify the span:
// Change only this occurrencetry eventStore.save(event, span: .thisEvent)// Change this and all future occurrencestry eventStore.save(event, span: .futureEvents)
Alarms
Attach alarms to events or reminders to trigger notifications.
// 15 minutes beforelet alarm = EKAlarm(relativeOffset: -15 * 60)event.addAlarm(alarm)// At an absolute datelet absoluteAlarm = EKAlarm(absoluteDate: alertDate)event.addAlarm(absoluteAlarm)
EventKitUI Controllers
EKEventEditViewController — Create/Edit Events
Present the system event editor for creating or editing events.
import EventKitUIclass EventEditorCoordinator: NSObject, EKEventEditViewDelegate {let eventStore = EKEventStore()func presentEditor(from viewController: UIViewController) {let editor = EKEventEditViewController()editor.eventStore = eventStoreeditor.editViewDelegate = selfviewController.present(editor, animated: true)}func eventEditViewController(_ controller: EKEventEditViewController,didCompleteWith action: EKEventEditViewAction) {switch action {case .saved:// Event savedbreakcase .canceled:breakcase .deleted:break@unknown default:break}controller.dismiss(animated: true)}}
EKEventViewController — View an Event
import EventKitUIlet viewer = EKEventViewController()viewer.event = existingEventviewer.allowsEditing = truenavigationController?.pushViewController(viewer, animated: true)
EKCalendarChooser — Select Calendars
let chooser = EKCalendarChooser(selectionStyle: .multiple,displayStyle: .allCalendars,entityType: .event,eventStore: eventStore)chooser.showsDoneButton = truechooser.showsCancelButton = truechooser.delegate = selfpresent(UINavigationController(rootViewController: chooser), animated: true)
Observing Changes
Register for EKEventStoreChanged notifications to keep your UI in sync when events are modified outside your app (e.g., by the Calendar app or a sync).
NotificationCenter.default.addObserver(forName: .EKEventStoreChanged,object: eventStore,queue: .main) { [weak self] _ inself?.refreshEvents()}
Always re-fetch events after receiving this notification. Previously fetched EKEvent objects may be stale.
Common Mistakes
DON'T: Use the deprecated requestAccess(to:) method
// WRONG: Deprecated in iOS 17eventStore.requestAccess(to: .event) { granted, error in }// CORRECT: Use the granular async methodslet granted = try await eventStore.requestFullAccessToEvents()
DON'T: Save events to a read-only calendar
// WRONG: No check -- will throw if calendar is read-onlyevent.calendar = someCalendartry eventStore.save(event, span: .thisEvent)// CORRECT: Verify the calendar allows modificationsguard someCalendar.allowsContentModifications else {event.calendar = eventStore.defaultCalendarForNewEventsreturn}event.calendar = someCalendartry eventStore.save(event, span: .thisEvent)
DON'T: Ignore timezone when creating events
// WRONG: Event appears at wrong time for traveling usersevent.startDate = Date()event.endDate = Date().addingTimeInterval(3600)// CORRECT: Set the timezone explicitly for location-specific eventsevent.timeZone = TimeZone(identifier: "America/New_York")event.startDate = startDateevent.endDate = endDate
DON'T: Forget to commit batched saves
// WRONG: Changes never persistedtry eventStore.save(event1, span: .thisEvent, commit: false)try eventStore.save(event2, span: .thisEvent, commit: false)// Missing commit!// CORRECT: Commit after batchingtry eventStore.save(event1, span: .thisEvent, commit: false)try eventStore.save(event2, span: .thisEvent, commit: false)try eventStore.commit()
DON'T: Mix EKObjects from different event stores
// WRONG: Event fetched from storeA, saved to storeBlet event = storeA.event(withIdentifier: id)!try storeB.save(event, span: .thisEvent) // Undefined behavior// CORRECT: Use the same store throughoutlet event = eventStore.event(withIdentifier: id)!try eventStore.save(event, span: .thisEvent)
Review Checklist
- [ ] Correct
Info.plistusage description keys added for calendars and/or reminders - [ ] Authorization requested with iOS 17+ granular methods (
requestFullAccessToEvents,requestWriteOnlyAccessToEvents,requestFullAccessToReminders) - [ ] Authorization status checked before fetching or saving
- [ ] Single
EKEventStoreinstance reused across the app - [ ] Events saved to a writable calendar (
allowsContentModificationschecked) - [ ] Recurring event saves specify correct
EKSpan(.thisEventvs.futureEvents) - [ ] Batched saves followed by explicit
commit() - [ ]
EKEventStoreChangednotification observed to refresh stale data - [ ] Timezone set explicitly for location-specific events
- [ ] EKObjects not shared across different event store instances
- [ ] EventKitUI delegates dismiss controllers in completion callbacks
References
- Extended patterns (SwiftUI wrappers, predicate queries, batch operations): references/eventkit-patterns.md
- EventKit framework
- EKEventStore
- EKEvent
- EKReminder
- EKRecurrenceRule
- EKCalendar
- EventKit UI
- EKEventEditViewController
- EKCalendarChooser
- Accessing the event store
- Creating a recurring event