Skip to content

Add a SwiftUI Calendar sample for iOS - #749

Open
rksharma-owg wants to merge 8 commits into
google:mainfrom
rksharma-owg:codex/swift-calendar-sample
Open

rksharma-owg wants to merge 8 commits into
google:mainfrom
rksharma-owg:codex/swift-calendar-sample

Conversation

@rksharma-owg

@rksharma-owg rksharma-owg commented Oct 12, 2026 •

Copy link
Copy Markdown

The existing Calendar example uses Objective-C and AppKit. Add a small iOS example showing how Swift can use the Calendar service with AppAuth/GTMAppAuth and read-only authorization.

The sample requires iOS 17 or later and uses Observation with main-actor models, SwiftUI State, and Swift Testing. It reads upcoming primary-calendar events, loads pages on demand, preserves earlier results after a page error, and clears pending/visible state on sign-out. It includes OAuth client and callback setup instructions, a checked-in Xcode project/shared scheme, offline coverage, and Debug/Release simulator coverage in the Examples workflow.

The review update replaces Combine observation and XCTest, retains all 18 behavioral cases, and splits the view into readable sections. It also merges current main to preserve the workflow policy updates. The client library's deployment targets are unchanged.

Validation at 39725e8 against main 2e7c517: 18 offline Swift Testing cases passed locally and on hosted macOS. All four existing examples passed Debug/Release builds, and regular zizmor passed in the full fork preflight. Its first Release simulator job failed before compilation because no destinations were available; both Debug and Release builds and all 18 cases then passed in the focused simulator preflight using the same source, baseline and test commands. The focused run adds simulator inventory/destination diagnostics; unrelated jobs are intentionally skipped there and are covered by the full run.

Offline tests cover query settings, paging/error/refresh/cancellation behavior, all-day date display, callback configuration, PKCE/read-only request construction, saved-session errors, and accepted/rejected callback handling. Live OAuth, actual Keychain operations, and Google Calendar access have not been tested with a configured client/account.

The changed Examples workflow pins checkout to v7.0.1, limits its token to repository reading, and disables persisted checkout credentials. Its regular zizmor 1.25.2 check has no findings. Auditor mode additionally reports fixed-literal matrix interpolation, unnamed-step, and concurrency suggestions; none is treated as proof of a source defect.

Related to #234.

#endif

@MainActor
final class CalendarAuthorization: ObservableObject {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: Is supporting iOS 15 critical https://developer.apple.com/documentation/observation? If not, I suggest refactoring the example to the modern Observation approach (requires iOS 17+). Combine framework seems to be mostly abandoned plus it doesn't really play nicely with Swift Concurrency.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably do that now as folks will likely be looking for references that go with Swift Concurrency.

} else if model.hasMore {
Button("Load More", action: model.loadMore).disabled(model.isLoading)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: it may be helpful to split body into smaller ViewBuilder helpers (e.g. a helper per section content) or subviews for readability.

import XCTest
@testable import SwiftCalendarSample

final class CalendarAuthorizationTests: XCTestCase {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: It seems like the test can be converted to the modern Swift Testing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This we should definitely be done.

Use main-actor observable models and SwiftUI State on iOS 17, preserve
initial and subsequent authorization updates, and split the view sections
for readability. Convert all 18 offline cases to Swift Testing, replacing
Combine/XCTest waits with event-driven continuations.

Merge current main while retaining its workflow policy updates and the
sample's Debug/Release simulator checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants