CtrlK
BlogDocsLog inGet started
Tessl Logo

thiennc-tesoglobal/ios-skills

Community-maintained Agent Skills for complete Swift and Apple-platform app delivery.

73

Quality

92%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Medium

Suggest reviewing before use

Overview
Quality
Evals
Security
Files

core-implementation.mdskills/eventkit/references/

EventKit Core Implementation Details

Read this reference when the task needs concrete setup, API wiring, or implementation recipes. Keep scope, workflow, non-obvious invariants, mistakes, and review gates in the parent SKILL.md.

Availability

  • iOS 17+: Use granular full/write-only request methods; legacy requestAccess(to:) no longer prompts and throws. The system event editor can create an event without app calendar access. For iOS 10–16, guard those APIs, use the legacy request plus NSCalendarsUsageDescription / NSRemindersUsageDescription; EventKitUI may also need NSContactsUsageDescription.
  • iOS 26+: The typed EKEventStore.EventStoreChanged / .changed message is available behind a guard. Keep EKEventStoreChanged for earlier systems.

Setup

Info.plist Keys

Add the usage description for the access path selected in Authorization. Do not request broader access merely to simplify the setup path.

The authorization-free system editor path needs no calendar usage string. Direct writes need write-only or full access; reads need full access. Reminders have only full access.

Event Store

Create a single EKEventStore instance and reuse it. Do not mix objects from different event stores.

import EventKit

let eventStore = EKEventStore()

Authorization

Request the narrowest access that matches the feature. Apply the versioned request path in Availability.

KeyAccess Level
NSCalendarsFullAccessUsageDescriptionRead + write events
NSCalendarsWriteOnlyAccessUsageDescriptionDirect write-only event creation
NSRemindersFullAccessUsageDescriptionRead + write reminders

Full Access to Events

Call try await eventStore.requestFullAccessToEvents() when the app needs to read, edit, delete, or fetch calendar events.

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.

Call try await eventStore.requestWriteOnlyAccessToEvents() before direct EventKit writes that do not use EKEventEditViewController.

Write-only access can create events but cannot fetch calendars or events, including app-created events. Use full access for later query, verification, modification, or sync.

Full Access to Reminders

Call try await eventStore.requestFullAccessToReminders() before reading, creating, editing, or deleting reminders.

Checking Authorization Status

Use EKEventStore.authorizationStatus(for: .event) or .reminder before work. Handle .notDetermined, .fullAccess, .writeOnly, .restricted, .denied, and @unknown default; only .fullAccess supports event/reminder reads.

Creating Events

func createEvent(
    title: String,
    startDate: Date,
    endDate: Date,
    calendar: EKCalendar? = nil
) throws {
    let event = EKEvent(eventStore: eventStore)
    event.title = title
    event.startDate = startDate
    event.endDate = endDate
    event.calendar = calendar ?? eventStore.defaultCalendarForNewEvents

    try eventStore.save(event, span: .thisEvent)
}

Setting a Specific Calendar

// List writable calendars
let calendars = eventStore.calendars(for: .event)
    .filter { $0.allowsContentModifications }

// Use the first writable calendar, or the default
let targetCalendar = calendars.first ?? eventStore.defaultCalendarForNewEvents
event.calendar = targetCalendar

Adding Structured Location

import CoreLocation

let location = EKStructuredLocation(title: "Apple Park")
location.geoLocation = CLLocation(latitude: 37.3349, longitude: -122.0090)
event.structuredLocation = location

Fetching Events

After the full-access gate in Authorization, use a date-range predicate to query events. The events(matching:) method returns occurrences of recurring events expanded within the range. Event predicates are capped to a four-year span, and events(matching:) / enumerateEvents(matching:using:) are synchronous and return only committed events.

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 = title
    reminder.calendar = eventStore.defaultCalendarForNewReminders()

    let dueDateComponents = Calendar.current.dateComponents(
        [.year, .month, .day, .hour, .minute],
        from: dueDate
    )
    reminder.dueDateComponents = dueDateComponents

    try 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 in
        eventStore.fetchReminders(matching: predicate) { reminders in
            continuation.resume(returning: reminders ?? [])
        }
    }
}

Completing a Reminder

func completeReminder(_ reminder: EKReminder) throws {
    reminder.isCompleted = true
    try eventStore.save(reminder, commit: true)
}

Recurrence Rules

Use EKRecurrenceRule to create repeating events or reminders.

Simple Recurrence

// Every week, indefinitely
let weeklyRule = EKRecurrenceRule(
    recurrenceWith: .weekly,
    interval: 1,
    end: nil
)
event.addRecurrenceRule(weeklyRule)

// Every 2 weeks, ending after 10 occurrences
let biweeklyRule = EKRecurrenceRule(
    recurrenceWith: .weekly,
    interval: 2,
    end: EKRecurrenceEnd(occurrenceCount: 10)
)

// Monthly, ending on a specific date
let monthlyRule = EKRecurrenceRule(
    recurrenceWith: .monthly,
    interval: 1,
    end: EKRecurrenceEnd(end: endDate)
)

Complex Recurrence

// Every Monday and Wednesday
let 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 occurrence
try eventStore.save(event, span: .thisEvent)

// Change this and all future occurrences
try eventStore.save(event, span: .futureEvents)

Alarms

Attach alarms to events or reminders to trigger notifications.

// 15 minutes before
let alarm = EKAlarm(relativeOffset: -15 * 60)
event.addAlarm(alarm)

// At an absolute date
let absoluteAlarm = EKAlarm(absoluteDate: alertDate)
event.addAlarm(absoluteAlarm)

For reminder geofences, put an EKStructuredLocation and .enter / .leave proximity on an EKAlarm, then add it to the reminder. See references/eventkit-patterns.md for the full location-based reminder pattern.

EventKitUI Controllers

EKEventEditViewController — Create/Edit Events

Present the system event editor for creating or editing events.

On the authorization-free path in Availability, the editor runs out of process with its own calendar access. Do not inspect the dismissed controller to learn what was saved; refetch only with separate full access.

import EventKitUI

class EventEditorCoordinator: NSObject, EKEventEditViewDelegate {
    let eventStore = EKEventStore()

    func presentEditor(from viewController: UIViewController) {
        let editor = EKEventEditViewController()
        editor.eventStore = eventStore
        editor.editViewDelegate = self
        viewController.present(editor, animated: true)
    }

    func eventEditViewController(
        _ controller: EKEventEditViewController,
        didCompleteWith action: EKEventEditViewAction
    ) {
        switch action {
        case .saved:
            // Event saved
            break
        case .canceled:
            break
        case .deleted:
            break
        @unknown default:
            break
        }
        controller.dismiss(animated: true)
    }
}

EKEventViewController — View an Event

import EventKitUI

let viewer = EKEventViewController()
viewer.event = existingEvent
viewer.allowsEditing = true
navigationController?.pushViewController(viewer, animated: true)

EKCalendarChooser — Select Calendars

EKCalendarChooser requires write-only or full calendar access. In write-only apps, the chooser behaves as writable-calendars-only and only allows a single writable calendar selection.

let chooser = EKCalendarChooser(
    selectionStyle: .multiple,
    displayStyle: .allCalendars,
    entityType: .event,
    eventStore: eventStore
)
chooser.showsDoneButton = true
chooser.showsCancelButton = true
chooser.delegate = self
present(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] _ in
    self?.refreshEvents()
}

Always re-fetch events after receiving this notification. Previously fetched EKEvent, EKReminder, and EKCalendar objects may be stale. The notification is posted on the main actor.

skills

.mcp.json

README.md

tile.json