Sample CodeiOS, iPadOS, Mac CatalystReviewed 2026-07-21View on Apple Developer

Accessing Calendar using EventKit and EventKitUI

At a glance

Item Summary
Purpose Choose and implement the appropriate Calendar access level in your app.
App architecture A Swift sample bundle with entry-bearing project variants DropinLessons, MonthlyEvents, RepeatingLessons, each leading to EventKit / EventKitUI APIs.
Main patterns View-controller organization, Delegate or data-source callbacks, Coordinator, Central store, SwiftUI environment injection, Binding-based state propagation
Project style 38 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── DropinLessons/
│   ├── DropinLessonsApp.swift
│   ├── ContentView.swift
│   ├── DatePickerView.swift
│   └── EventEditViewController.swift
├── MonthlyEvents/
│   ├── MonthlyEventsApp.swift
│   ├── ContentView.swift
│   └── WelcomeView.swift
├── RepeatingLessons/
│   ├── RepeatingLessonsApp.swift
│   └── ContentView.swift
└── Shared/
    ├── MessageView.swift
    ├── EventDataStore.swift
    └── EventStoreManager.swift

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: Swift.
  • The verified tree contains 5 project/configuration file(s) and 34 source declaration(s).

Overall architecture

Reference code

DropinLessons/DropinLessonsApp.swift:10 — architecture anchor

@main
struct DropInLessonsApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Interpretation

The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.

Ownership and state

Ownership evidence

DropinLessons/ContentView.swift:11 — stored dependency or nearest verified ownership anchor

    @StateObject private var model: LessonModel = LessonModel(date: Date())
Owner Object or state Relationship Mutation authority
ContentView LessonModel (model) owns wrapper-managed state Owning lexical scope
DatePickerView Date (displayDate) borrows mutable state The upstream binding owner is authoritative
DatePickerView ClosedRange (dateRange) stores or receives Initialized by the owner; the binding is immutable
EventEditViewController EKEvent (event) borrows mutable state The upstream binding owner is authoritative

Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.

Class and protocol design

DropinLessons/DropinLessonsApp.swift:11 — representative type boundary

struct DropInLessonsApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
Type Responsibility Depends on or conforms to
DropInLessonsApp Application entry and top-level composition App
MonthlyEventsApp Application entry and top-level composition App
RepeatingLessonsApp Application entry and top-level composition App
MessageView User-interface presentation and input forwarding View
ContentView User-interface presentation and input forwarding View
DatePickerView User-interface presentation and input forwarding View
EventEditViewController View lifecycle, callbacks, and feature coordination UIViewControllerRepresentable
Coordinator Cross-object flow or session coordination NSObject, EKEventEditViewDelegate
ContentView User-interface presentation and input forwarding View
WelcomeView User-interface presentation and input forwarding View

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
model (DropinLessons/ContentView.swift:11) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
selectedEvent (DropinLessons/DropinLessonPicker.swift:15) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
showEventEditViewController (DropinLessons/DropinLessonPicker.swift:16) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
shouldPresentError (DropinLessons/DropinLessonPicker.swift:17) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.

Reference code

DropinLessons/ContentView.swift:11 — representative boundary

    @StateObject private var model: LessonModel = LessonModel(date: Date())

Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.

Logic ownership and placement

Logic Owning type or file Placement rationale
Application entry and top-level composition DropInLessonsApp, MonthlyEventsApp, RepeatingLessonsApp The source’s App suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination EventEditViewController The source’s Controller suffix makes this role explicit.
Cross-object flow or session coordination Coordinator The source’s Coordinator suffix makes this role explicit.
Long-lived feature or framework coordination EventStoreManager The source’s Manager suffix makes this role explicit.
Feature data or observable state LessonModel The source’s Model suffix makes this role explicit.
Centralized state or persistence access EventDataStore The source’s Store suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, DatePickerView, MessageView, WelcomeView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization DropinLessons/EventEditViewController.swift:12 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Delegate or data-source callbacks DropinLessons/EventEditViewController.swift:35 Callback protocols invert event delivery back into the sample’s owner.
Coordinator DropinLessons/EventEditViewController.swift:35 A role-named coordinator centralizes cross-object flow.
Central store Shared/EventDataStore.swift:10 A store-named type centralizes feature state or persistence.
SwiftUI environment injection MonthlyEvents/EventList.swift:12 The environment supplies state or a capability without threading it through every initializer.
Binding-based state propagation DropinLessons/DatePickerView.swift:11 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: App: DropInLessonsApp, MonthlyEventsApp, RepeatingLessonsApp; Controller: EventEditViewController; Coordinator: Coordinator; Manager: EventStoreManager; Model: LessonModel; Store: EventDataStore; View: ContentView, DatePickerView, MessageView, WelcomeView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: makeUIViewController, updateUIViewController, makeCoordinator, eventEditViewController.
  • Files: MonthlyEvents/MonthlyEventsApp.swift, RepeatingLessons/RepeatingLessonsApp.swift, Shared/MessageView.swift, DropinLessons/ContentView.swift, DropinLessons/DatePickerView.swift, DropinLessons/EventEditViewController.swift.

Architecture takeaways

  • DropinLessonsApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, EventKit, EventKitUI through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
  • Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
  • Access-control conclusions separate verified language visibility from the likely design rationale.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
DropinLessons/DropinLessonsApp.swift DropInLessonsApp
MonthlyEvents/MonthlyEventsApp.swift MonthlyEventsApp
RepeatingLessons/RepeatingLessonsApp.swift RepeatingLessonsApp
Shared/MessageView.swift Message, MessageView, MessageView_Previews
DropinLessons/ContentView.swift ContentView, ContentView_Previews
DropinLessons/DatePickerView.swift DatePickerView, DatePickerView_Previews
DropinLessons/EventEditViewController.swift EventEditViewController, Coordinator
MonthlyEvents/ContentView.swift ContentView, ContentView_Previews
MonthlyEvents/WelcomeView.swift WelcomeView, WelcomeView_Previews
RepeatingLessons/ContentView.swift ContentView, ContentView_Previews