Add To Calendar Without Promising To Keep It In Sync

Someone books a workshop, taps Add to Calendar, and saves it. A week later, your app moves the workshop to another time.

Should the button still say “Added”? Did the Calendar event move too? Can the app check?

For a simple export through Apple’s system editor, the last two answers are no. The first deserves better wording. A calendar export is a photocopy, not a subscription.

Let’s build an export that remembers which version of a workshop it offered, keeps an open editor stable during source changes, and warns before creating another copy. It asks for no calendar-reading permission and makes no synchronization promise.

Choose the right kind of calendar integration

From iOS 17, EKEventEditViewController runs its editor outside your app’s process. A person can review and save an event there without giving your app calendar access. This is an established capability, still useful on current systems—not an iOS 27 addition. Apple’s event-store access guide explains the distinction.

Choose the contract your feature actually needs:

  • One event, reviewed by the person: present EventKitUI. This article takes that path.
  • Directly create events: request write-only access and provide its usage description. That permission does not let your app read back events, including ones it created.
  • Read or update existing events: full access is a separate product decision, with its own permission and synchronization design.

A Stack Overflow permission-migration question already has answers pointing out the editor-only path. We are extending the integration beyond that fix: what should the app remember after saving?

Apple’s Calendar access sample supplies the crucial limit. The person can change the title, dates, or destination calendar in the system editor. Inspecting the dismissed controller’s event does not reveal those final edits to this app. A .saved callback is an outcome, not a returned event snapshot.

Filip Němeček’s SwiftUI wrapper article is a useful starting point for the coordinator bridge. Here we add request ownership and a receipt that describes only what the app knows.

Give each presentation its own snapshot

The complete example targets iOS 17 or later, uses Swift 6.2-or-later isolation syntax, and was checked with Xcode 27.1 and Swift 6.4. Paste the three Swift blocks below into one file, in order, and show WorkshopView() from an iOS app’s existing window. The downloadable Xcode project includes the complete example and tests.

For this editor-only target, no calendar usage-description keys or authorization request are needed. If another feature directly accesses Calendar, keep its appropriate permission setup; this is not advice to remove it from the whole app.

We need two identities: the workshop’s stable ID and a fresh ID for each export attempt. The revision belongs to the app’s source data. Increment it whenever an exported field changes; a real backend can supply an equivalent version token.

import Foundation

nonisolated struct Workshop: Sendable {
    let id: UUID
    var revision: Int
    var title: String
    var start: Date
    var end: Date
    let timeZone: TimeZone
}

nonisolated struct CalendarExportRequest: Identifiable, Sendable {
    let id = UUID()
    let workshop: Workshop
}

nonisolated struct ExportReceipt: Equatable, Sendable {
    let attemptID: UUID
    let workshopID: UUID
    let sourceRevision: Int
}

nonisolated enum ExportOutcome: Sendable {
    case saved, cancelled, deleted, unknown
}

nonisolated enum ExportError: Error {
    case invalidWorkshop
}

nonisolated struct ExportFlow {
    private(set) var presentation: CalendarExportRequest?
    private(set) var isDismissing = false
    private(set) var receipt: ExportReceipt?

    var isBusy: Bool { presentation != nil || isDismissing }

    mutating func begin(_ workshop: Workshop) throws {
        guard !isBusy else { return }
        guard !workshop.title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty,
              workshop.start.timeIntervalSince1970.isFinite,
              workshop.end.timeIntervalSince1970.isFinite,
              workshop.end > workshop.start else {
            throw ExportError.invalidWorkshop
        }
        presentation = CalendarExportRequest(workshop: workshop)
    }

    mutating func complete(attemptID: UUID, outcome: ExportOutcome) {
        guard let request = presentation, request.id == attemptID else { return }
        if case .saved = outcome {
            receipt = ExportReceipt(
                attemptID: request.id,
                workshopID: request.workshop.id,
                sourceRevision: request.workshop.revision
            )
        }
        dismiss()
    }

    mutating func dismiss() {
        guard presentation != nil else { return }
        presentation = nil
        isDismissing = true
    }

    mutating func didDismiss() {
        isDismissing = false
    }
}

begin copies the workshop. Changing the source afterward cannot rewrite that request. It also rejects empty titles, invalid dates, and a nonpositive duration before opening the editor.

Only .saved produces a receipt. Cancel, delete, an unknown future action, and dismissal leave the previous receipt alone. This is a last reported save, not a history of every attempt.

The attempt ID rejects stale completions. The small dismissal flag keeps another presentation from starting between clearing the sheet item and SwiftUI’s onDismiss. Call didDismiss() from that callback, not immediately after requesting dismissal.

None of this prevents duplicate events across devices or app launches. It prevents this screen from confusing one presentation with another.

Create the event once

The wrapper retains the same EKEventStore for both the event and the controller. It deliberately leaves the calendar unset so the system editor can provide its default and let the person choose.

import SwiftUI
import EventKit
import EventKitUI

@MainActor
struct CalendarExportSheet: UIViewControllerRepresentable {
    let request: CalendarExportRequest
    let store: EKEventStore
    var onCompletion: @MainActor (UUID, ExportOutcome) -> Void

    func makeCoordinator() -> Coordinator {
        Coordinator(request: request, store: store, onCompletion: onCompletion)
    }

    func makeUIViewController(context: Context) -> EKEventEditViewController {
        let coordinator = context.coordinator
        let workshop = coordinator.request.workshop
        let event = EKEvent(eventStore: coordinator.store)
        event.title = workshop.title
        event.startDate = workshop.start
        event.endDate = workshop.end
        event.timeZone = workshop.timeZone

        let controller = EKEventEditViewController()
        controller.eventStore = coordinator.store
        controller.event = event
        controller.editViewDelegate = coordinator
        return controller
    }

    func updateUIViewController(
        _ controller: EKEventEditViewController, context: Context
    ) {
        context.coordinator.onCompletion = onCompletion
    }

    @MainActor
    final class Coordinator: NSObject, @MainActor EKEventEditViewDelegate {
        let request: CalendarExportRequest
        let store: EKEventStore
        var onCompletion: @MainActor (UUID, ExportOutcome) -> Void
        private var completed = false

        init(request: CalendarExportRequest, store: EKEventStore,
             onCompletion: @escaping @MainActor (UUID, ExportOutcome) -> Void) {
            self.request = request
            self.store = store
            self.onCompletion = onCompletion
        }

        func eventEditViewController(
            _ controller: EKEventEditViewController,
            didCompleteWith action: EKEventEditViewAction
        ) {
            guard !completed else { return }
            completed = true
            let outcome: ExportOutcome
            switch action {
            case .saved: outcome = .saved
            case .canceled: outcome = .cancelled
            case .deleted: outcome = .deleted
            @unknown default: outcome = .unknown
            }
            onCompletion(request.id, outcome)
        }
    }
}

makeUIViewController initializes the editor from the coordinator’s original snapshot. updateUIViewController refreshes the callback only. Assigning the latest source title or time there could overwrite the person’s work whenever SwiftUI refreshes the wrapper.

The coordinator and its delegate conformance are explicitly MainActor-isolated. This uses Swift’s isolated conformance syntax for the UIKit boundary; the annotation does not dispatch a callback onto another actor.

The delegate translates the result once and lets the parent dismiss. It does not call eventStore.save afterward: the editor already performed the save. Nor does it inspect controller.event to invent a final title, date, or identifier.

If you add a programmatic cancelEditing() path, remember that Apple’s controller contract says that method does not invoke the completion delegate. Dismiss your presentation explicitly. Do not interpret a disappearing sheet as a save.

Show what the receipt actually means

This view owns one workshop and one store for its lifetime. The demo button moves the source by one elapsed hour and increments its revision. It models a changed booking; it is not a recurring-time or daylight-saving scheduling algorithm.

@MainActor
struct WorkshopView: View {
    @State private var workshop = Workshop(
        id: UUID(), revision: 1, title: "A better app workshop",
        start: Date(timeIntervalSince1970: 1_793_208_600),
        end: Date(timeIntervalSince1970: 1_793_212_200),
        timeZone: TimeZone(identifier: "America/Denver")!
    )
    @State private var flow = ExportFlow()
    @State private var store = EKEventStore()
    @State private var errorMessage: String?
    @State private var confirmingAnotherCopy = false

    private var editor: Binding<CalendarExportRequest?> {
        Binding(get: { flow.presentation }, set: { value in
            if value == nil { flow.dismiss() }
        })
    }

    private var receiptMessage: String? {
        guard let receipt = flow.receipt,
              receipt.workshopID == workshop.id else { return nil }
        if receipt.sourceRevision == workshop.revision {
            return "Calendar reported a save from these workshop details."
        }
        return "This workshop changed after your last export. "
            + "Your Calendar copy has not been updated by this app."
    }

    var body: some View {
        NavigationStack {
            Form {
                Section("Workshop") {
                    Text(workshop.title)
                    Text(workshop.start.formatted(Date.FormatStyle(
                        date: .abbreviated, time: .shortened,
                        timeZone: workshop.timeZone)))
                    Text("Time zone: \(workshop.timeZone.identifier)")
                        .font(.caption)
                    Button("Move workshop one hour later (demo)") {
                        workshop.start.addTimeInterval(3600)
                        workshop.end.addTimeInterval(3600)
                        workshop.revision += 1
                    }
                }
                Section {
                    Button("Add to Calendar") {
                        if receiptMessage != nil {
                            confirmingAnotherCopy = true
                        } else {
                            beginExport()
                        }
                    }
                    .disabled(flow.isBusy)
                    if let receiptMessage { Text(receiptMessage) }
                    if let errorMessage { Text(errorMessage).foregroundStyle(.red) }
                } footer: {
                    Text("Calendar saves an independent copy. You can change it "
                        + "in the editor, and later changes are not synchronized. "
                        + "This screen remembers saves only while it stays open.")
                }
            }
            .navigationTitle("Workshop")
            .confirmationDialog("Add another Calendar copy?",
                                isPresented: $confirmingAnotherCopy,
                                titleVisibility: .visible) {
                Button("Add another copy") { beginExport() }
            } message: {
                Text("The previous copy may still exist. This adds a new event; "
                    + "it does not update the previous one.")
            }
            .sheet(item: editor, onDismiss: { flow.didDismiss() }) { request in
                CalendarExportSheet(request: request, store: store) { id, outcome in
                    flow.complete(attemptID: id, outcome: outcome)
                }
            }
        }
    }

    private func beginExport() {
        do {
            try flow.begin(workshop)
            errorMessage = nil
        } catch {
            errorMessage = "This workshop needs a title and a valid time range."
        }
    }
}

The receipt compares the workshop ID and source revision. When they still match, the message says Calendar reported a save from these details. It does not say the person saved those exact details, or that the event still exists.

After rescheduling, the message says this app has not updated the Calendar copy. That remains true even if the person independently fixed it in Calendar; this screen cannot inspect that change.

The second export requires a deliberate “Add another copy” action. Cancelling it preserves the earlier receipt. Saving it replaces the receipt with the revision offered for that attempt. Updating an existing Calendar event would require a different feature, not a quieter button label.

The example keeps its receipt only while the view’s state survives. It is useful feedback for this screen, not durable duplicate prevention. If your product needs the reminder after a relaunch, persist the app-owned workshop ID and revision with your normal storage layer and scope them to the correct account. A persisted receipt still cannot prove the Calendar event remains present.

This resembles choosing a contact email without address-book access, with one important difference: the contact picker returns a chosen value. This calendar editor returns an editing outcome. Design the local state around the result you actually receive.

Test the awkward transitions

The downloadable project exercises the exact article declarations. Its native UI tests edit the title in the real system editor, save, reschedule the source, and cancel a second export. A separate instrumented host changes the source while the editor is open: the person’s title edit stays intact, and the save receipt still identifies the original source revision.

The checks also cover parent-driven dismissal without a save callback, cancel and reopen, stale or duplicate completion IDs, the dismissal window, and invalid workshop details. The test app contains no calendar or contacts usage-description keys. On the tested simulator, authorization remains .notDetermined before and after the editor reports a save.

Verified October 21, 2026: the complete three-block example compiles for an iOS 17 deployment target with Xcode 27.1 / Swift 6.4, in ordinary and MainActor default-isolation modes. Value-model tests run on macOS; the editor and view interactions run on iOS 27 Simulator in both modes. Large Dynamic Type receives limited automated accessibility checks, not a claim of VoiceOver testing. No physical-device, older-runtime, final-event readback, or cross-device synchronization test is implied.

Before shipping, exercise your supported devices and calendar-account configurations, including any restrictions that could prevent an event from being saved. Let the system editor handle its save UI, and only record success when it reports .saved.