Implementing age assurance and permissions
At a glance
| Item | Summary |
|---|---|
| Purpose | Present a significant-change flow that asks for the person’s age range, then either shows an adult acknowledgment, requests parental approval through PermissionKit, or blocks the UI. |
| App architecture | One SwiftUI app target. The App creates two @MainActor @Observable objects, ComplianceManager (regulatory requirements) and SignificantChangeVersionManager (which changes still need handling), and injects both through the SwiftUI environment. The version manager wraps a private SignificantChangeVersion object that persists handled changes in NSUbiquitousKeyValueStore. |
| Main patterns | SwiftUI environment injection, @Observable state, and a @Bindable sheet binding. The age-range decision itself lives in a SignificantChangeView with local @State. |
| Project style | Thirteen flat Swift files in AgeAssuranceAndPermissions/: entry, two observable state owners, one persistence class, one value type with a static change list, five flow and content views, and a Helpers.swift of enums and extensions. |
| Execution model | SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor plus explicit @MainActor on the three classes. Work starts from a SwiftUI .task, from plain Task {} blocks in views and managers, and from one unstored notification loop. |
| State/event model | @Observable properties read through @Environment; NotificationCenter.notifications(named:) for iCloud key-value changes; AskCenter.shared.responses(for:) async sequence for parental answers. |
| Key frameworks/packages | DeclaredAgeRange, PermissionKit, StoreKit (AppTransaction), SwiftUI, OSLog, MapKit, AVKit. The project declares no Swift package. |
Project structure
AgeAssuranceAndPermissions.xcodeproj/ one app target, no Swift packages
AgeAssuranceAndPermissions/
├── AgeAssuranceAndPermissionsApp.swift @main; owns both managers; parental-answer loop
├── ComplianceManager.swift @Observable; AgeRangeService regulatory features
├── SignificantChangeVersionManager.swift @Observable; sheet flag, change description, handle*()
├── SignificantChangeVersion.swift @Observable; NSUbiquitousKeyValueStore + AppTransaction
├── SignificantChange.swift value type + static allChanges list
├── Helpers.swift SignificantChangePhase, AgeRangeResult, SignificantChangeError
├── ContentView.swift error view or ImageView + significant-change sheet
├── SignificantChangeView.swift requestAgeRange flow and result handling
├── SignificantChangeInformationView.swift explanatory text + Continue button
├── RequestParentalApprovalView.swift PermissionButton for the parent request
├── ImageView.swift, MapView.swift, VideoPlayerView.swift gated content
└── AgeAssuranceAndPermissions.entitlements declared-age-range + ubiquity-kvstore
Structure observations
- The entitlements enable the Declared Age Range capability and an iCloud key-value store (
AgeAssuranceAndPermissions/AgeAssuranceAndPermissions.entitlements:5,AgeAssuranceAndPermissions/AgeAssuranceAndPermissions.entitlements:7). Those two entitlements match the two persistent concerns in code: age range and handled-change records. - New significant changes are added as data, not code paths: each
SignificantChangehas anidandintroducedInVersion, collected instatic let allChanges(AgeAssuranceAndPermissions/SignificantChange.swift:29). Helpers.swiftholds the flow’s decision types, includingAgeRangeResult.from(_:), which maps anAgeRangeService.Responseinto four cases (AgeAssuranceAndPermissions/Helpers.swift:47).
Platform boundary
The DocC record lists iOS, iPadOS, and Mac Catalyst. The app target sets SUPPORTED_PLATFORMS = "iphoneos iphonesimulator", SUPPORTS_MACCATALYST = NO, and SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO (AgeAssuranceAndPermissions.xcodeproj/project.pbxproj:391, AgeAssuranceAndPermissions.xcodeproj/project.pbxproj:392, AgeAssuranceAndPermissions.xcodeproj/project.pbxproj:393), so the source builds only for iPhone and iPad.
Overall architecture
flowchart LR
App["AgeAssuranceAndPermissionsApp"] -->|"@State + .environment"| CM["ComplianceManager"]
App -->|"@State + .environment"| VM["SignificantChangeVersionManager"]
VM -->|"private let store"| Store["SignificantChangeVersion"]
Store --> KVS["NSUbiquitousKeyValueStore / AppTransaction"]
CM --> ARS["AgeRangeService.shared"]
App --> Content["ContentView"]
Content -->|"sheet when showSignificantChangeView"| Flow["SignificantChangeView"]
Flow -->|"requestAgeRange / acknowledgment"| DAR["DeclaredAgeRange environment actions"]
Flow --> Parent["RequestParentalApprovalView (PermissionButton)"]
App -->|"AskCenter responses"| VM
Reference code
AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:26 — launch sequence
@main
struct AgeAssuranceAndPermissionsApp: App {
@State private var complianceManager = ComplianceManager()
@State private var versionManager = SignificantChangeVersionManager()
// ...
var body: some Scene {
WindowGroup {
ContentView()
.task {
await complianceManager.identifyRegulatoryRequirements()
if complianceManager.isComplianceRequired {
await versionManager.synchronize()
for await response in AskCenter.shared.responses(for: SignificantAppUpdateTopic.self) {
guard response.choice.answer == .approval else {
// The parent or guardian denies their minor's request. The minor can no longer use the app.
return
}
// Mark all significant changes as handled.
versionManager.handleAllChanges()
}
}
}
.environment(complianceManager)
.environment(versionManager)
}
}
}Interpretation
Observed: the app entry is the composition root and also the only listener for parental answers. The sheet appears only when synchronize() finds unhandled changes, which happens only after ComplianceManager reports at least one regulatory feature (AgeAssuranceAndPermissions/ComplianceManager.swift:39). Outside a regulated region, the flow never runs and ImageView is shown directly.
Observed: the decision of what to do with an age range is in a view, not a manager. SignificantChangeView.handleResult(_:) combines the parsed AgeRangeResult with ComplianceManager.requiresParentalConsent or requiresAdultNotification (AgeAssuranceAndPermissions/SignificantChangeView.swift:88). Inference: the system actions it calls (requestAgeRange, showSignificantUpdateAcknowledgment) are SwiftUI environment values, so the logic sits where those values are available.
Ownership and state
classDiagram
AgeAssuranceAndPermissionsApp *-- ComplianceManager : @State private var
AgeAssuranceAndPermissionsApp *-- SignificantChangeVersionManager : @State private var
SignificantChangeVersionManager *-- SignificantChangeVersion : private let store
SignificantChangeVersion o-- NSUbiquitousKeyValueStore : default, private let
ContentView o-- ComplianceManager : @Environment
ContentView o-- SignificantChangeVersionManager : @Environment + @Bindable
SignificantChangeView o-- ComplianceManager : @Environment
SignificantChangeView o-- SignificantChangeVersionManager : @Environment
SignificantChangeView *-- FlowState : @State phase, parentalQuestion, flowError
Ownership evidence
AgeAssuranceAndPermissions/SignificantChangeVersionManager.swift:13 — the version manager wraps its persistence object
@MainActor
@Observable final class SignificantChangeVersionManager {
private let store: SignificantChangeVersion
// ...
var showSignificantChangeView: Bool
// ...
init() {
self.store = SignificantChangeVersion()
self.showSignificantChangeView = false
}
func synchronize() async {
await store.fetchLatest()
showSignificantChangeView = store.hasFetched && !unhandledChanges.isEmpty
}
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AgeAssuranceAndPermissionsApp |
ComplianceManager, SignificantChangeVersionManager |
Creates both in @State private var and injects them with .environment (AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:14, AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:41) |
Each manager mutates its own state |
ComplianceManager |
isComplianceRequired, fetchError |
Implicitly internal vars, set in identifyRegulatoryRequirements() |
ComplianceManager |
ComplianceManager |
regulatoryFeatures |
private var, exposed only as requiresParentalConsent / requiresAdultNotification (AgeAssuranceAndPermissions/ComplianceManager.swift:27) |
ComplianceManager |
SignificantChangeVersionManager |
SignificantChangeVersion |
Creates it in init and keeps it private let |
Manager calls fetchLatest() and markAsHandled(_:) |
SignificantChangeVersionManager |
showSignificantChangeView |
Set by synchronize(); also written through the @Bindable sheet binding when the sheet closes |
Manager and ContentView binding |
SignificantChangeVersion |
handledChanges, hasFetched |
private var and private(set) var (AgeAssuranceAndPermissions/SignificantChangeVersion.swift:14, AgeAssuranceAndPermissions/SignificantChangeVersion.swift:15) |
SignificantChangeVersion |
SignificantChangeVersion |
NSUbiquitousKeyValueStore.default |
Stores the shared system store in private let (AgeAssuranceAndPermissions/SignificantChangeVersion.swift:46) |
markAsHandled(_:) writes; syncFromUbiquitousStore() reads |
SignificantChangeView |
phase, formattedAgeRange, flowError, showAlert, parentalQuestion |
Local @State private var (AgeAssuranceAndPermissions/SignificantChangeView.swift:21) |
SignificantChangeView |
Observed: SignificantChangeVersion is itself @Observable, but no view reads it; only the manager does. unhandledChanges on the manager is computed from the store, so observation reaches views through the store’s tracked properties.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Default isolation | SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor, Swift 6 |
Undecorated views and helpers are main-actor isolated by build setting | AgeAssuranceAndPermissions.xcodeproj/project.pbxproj:396, AgeAssuranceAndPermissions.xcodeproj/project.pbxproj:399 |
| Explicit isolation | @MainActor on all three classes |
Manager and store state is main-actor isolated | AgeAssuranceAndPermissions/ComplianceManager.swift:11, AgeAssuranceAndPermissions/SignificantChangeVersionManager.swift:11, AgeAssuranceAndPermissions/SignificantChangeVersion.swift:11 |
| Concurrency import boundary | @preconcurrency import DeclaredAgeRange |
Relaxes Sendable diagnostics for that framework’s types in two files | AgeAssuranceAndPermissions/ComplianceManager.swift:9, AgeAssuranceAndPermissions/SignificantChangeView.swift:8 |
| SwiftUI-managed task | .task { ... for await response in AskCenter.shared.responses(...) } |
Launch checks and the parental-answer loop run in one task tied to ContentView; a denial returns and ends the loop |
AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:25, AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:30 |
| Unstored notification loop | Task { for await _ in NotificationCenter.default.notifications(named: ...) } in init |
Created once by SignificantChangeVersion; not stored, so nothing cancels it |
AgeAssuranceAndPermissions/SignificantChangeVersion.swift:50, AgeAssuranceAndPermissions/SignificantChangeVersion.swift:55 |
| Fire-and-forget resync | Task { await synchronize() } after markAsHandled |
Plain tasks from main-actor methods; not stored | AgeAssuranceAndPermissions/SignificantChangeVersionManager.swift:43, AgeAssuranceAndPermissions/SignificantChangeVersionManager.swift:51 |
| View-started tasks | Task { try await requestAgeRange(ageGates:) }, Task { try await showSignificantUpdateAdultAcknowledgment(...) } |
Plain tasks in main-actor view methods; results update @State and managers directly |
AgeAssuranceAndPermissions/SignificantChangeView.swift:69, AgeAssuranceAndPermissions/SignificantChangeView.swift:133 |
| Async property | private var originalAppVersion: String? { get async } |
Awaits AppTransaction.shared and returns only a verified original version |
AgeAssuranceAndPermissions/SignificantChangeVersion.swift:23 |
Reference code
AgeAssuranceAndPermissions/SignificantChangeVersion.swift:50 — unstored notification loop started in init
init() {
let ubiquitousStore = NSUbiquitousKeyValueStore.default
self.ubiquitousStore = ubiquitousStore
self.handledChanges = []
Task {
// Listen for external changes from other devices.
let notifications = NotificationCenter.default.notifications(named: NSUbiquitousKeyValueStore.didChangeExternallyNotification)
// Asynchronously iterate over notifications.
for await _ in notifications {
syncFromUbiquitousStore()
}
}
}Interpretation: all mutable state lives on the main actor, so there is no lock or queue. The object that creates the notification task lives for the app’s lifetime (it is owned by @State in the App), which is why the unstored task is harmless here. Inference: the loop holds a strong reference to self for as long as it runs.
State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| Environment injection | .environment(complianceManager), .environment(versionManager) read with @Environment(Type.self) |
Both managers reach ContentView and SignificantChangeView without initializer parameters |
AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:41, AgeAssuranceAndPermissions/ContentView.swift:11, AgeAssuranceAndPermissions/SignificantChangeView.swift:14 |
| Binding | @Bindable var versionManager = versionManager and .sheet(isPresented: $versionManager.showSignificantChangeView) |
The manager’s flag drives the sheet | AgeAssuranceAndPermissions/ContentView.swift:15, AgeAssuranceAndPermissions/ContentView.swift:26 |
| System actions | @Environment(\.requestAgeRange), @Environment(\.showSignificantUpdateAcknowledgment) |
Age-range request and adult acknowledgment are environment-provided async actions | AgeAssuranceAndPermissions/SignificantChangeView.swift:18, AgeAssuranceAndPermissions/SignificantChangeView.swift:19 |
| Parent request | PermissionQuestion(significantAppUpdateTopic:) shown through PermissionButton |
The view creates the question; the app’s AskCenter loop consumes the answer |
AgeAssuranceAndPermissions/SignificantChangeView.swift:110, AgeAssuranceAndPermissions/RequestParentalApprovalView.swift:45 |
| Cross-device state | NSUbiquitousKeyValueStore keys named by SignificantChange.id |
Handled changes sync through iCloud; external changes arrive by notification | AgeAssuranceAndPermissions/SignificantChangeVersion.swift:119, AgeAssuranceAndPermissions/SignificantChangeVersion.swift:52 |
| Framework import | StoreKit |
AppTransaction for the original app version |
AgeAssuranceAndPermissions/SignificantChangeVersion.swift:8 |
| Framework import | PermissionKit, OSLog, SwiftUI |
App entry: AskCenter, the global logger, scenes |
AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:9, AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:47 |
| Framework import | MapKit, AVKit |
Gated content views only | AgeAssuranceAndPermissions/MapView.swift:8, AgeAssuranceAndPermissions/VideoPlayerView.swift:8 |
| Package declaration | None | The project file declares no Swift package | AgeAssuranceAndPermissions.xcodeproj/project.pbxproj:391 |
The source uses no Combine, so there is no receive(on:) or subscribe(on:) scheduling.
Class and protocol design
classDiagram
class AgeRangeResult {
<<enumeration>>
minor
verifiedAdult
unverifiedAdult
declinedSharing
from(response)
}
class SignificantChangePhase {
<<enumeration>>
idle
retrieving
blocked
}
SignificantChangeView --> AgeRangeResult : parses response
SignificantChangeView --> SignificantChangePhase : @State phase
SignificantChangeView --> SignificantChangeInformationView : phase + action closure
SignificantChangeVersionManager --> SignificantChangeVersion
SignificantChangeVersion --> SignificantChange : allChanges
Reference code
AgeAssuranceAndPermissions/Helpers.swift:47 — response parsing
static func from(_ response: AgeRangeService.Response) -> AgeRangeResult {
let ageOfMajority = 18
switch response {
case .declinedSharing:
// The person declined sharing their age range.
return .declinedSharing
case .sharing(range: let range):
// Determine whether the person is a minor or an adult.
if let upperBound = range.upperBound, upperBound < ageOfMajority {
// The person is under 18.
return .minor(ageRange: range.formattedText)
}
// ...
if let declaration = range.ageRangeDeclaration, declaration != .confirmed {
// The person is an unverified adult.
return .unverifiedAdult
}
// The person is a verified adult.
return .verifiedAdult(ageRange: range.formattedText)
@unknown default:
// The person is an unverified adult.
return .unverifiedAdult
}
}| Type | Responsibility | Depends on |
|---|---|---|
ComplianceManager |
Fetches requiredRegulatoryFeatures and exposes two Boolean policies |
AgeRangeService.shared |
SignificantChangeVersionManager |
UI-facing facade: sheet flag, change description, handleAllChanges() / handlePendingChanges() |
SignificantChangeVersion |
SignificantChangeVersion |
Persistence and install-version comparison | NSUbiquitousKeyValueStore, AppTransaction |
SignificantChange |
Hashable, Identifiable value with a static catalog |
none |
AgeRangeResult, SignificantChangePhase, SignificantChangeError |
Flow decision values and a LocalizedError |
DeclaredAgeRange |
SignificantChangeInformationView |
Stateless view: let phase, let action: () -> Void |
SignificantChangePhase |
Observed: the sample declares no local protocol. Callbacks between views are plain closures (SignificantChangeInformationView(phase:action:)).
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
complianceManager, versionManager in the App (AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:14) |
private @State |
Other types reach the managers only through the environment | Inference: one creation point, many readers. |
ComplianceManager.regulatoryFeatures (AgeAssuranceAndPermissions/ComplianceManager.swift:27) |
private |
Views see two derived Booleans, not the raw feature set | Inference: views ask policy questions instead of interpreting framework enums. |
ComplianceManager.isComplianceRequired, fetchError (AgeAssuranceAndPermissions/ComplianceManager.swift:14) |
implicit internal |
Any module type could assign them; only the manager does | No single-writer guarantee in the type system. |
SignificantChangeVersionManager.store (AgeAssuranceAndPermissions/SignificantChangeVersionManager.swift:13) |
private let |
Views cannot reach persistence directly | Inference: the manager is the only path for marking changes handled. |
SignificantChangeVersion.hasFetched (AgeAssuranceAndPermissions/SignificantChangeVersion.swift:15) |
private(set) |
Readable by the manager; set only by fetchLatest() |
Keeps “not fetched yet” distinct from “nothing to handle”. |
syncFromUbiquitousStore(), performFetch(), originalAppVersion (AgeAssuranceAndPermissions/SignificantChangeVersion.swift:70, AgeAssuranceAndPermissions/SignificantChangeVersion.swift:78) |
private |
Internal steps of fetchLatest() and the notification loop |
Inference: callers use only fetchLatest() and markAsHandled(_:). |
startFlow(), handleResult(_:), presentSignificantChanges() (AgeAssuranceAndPermissions/SignificantChangeView.swift:67) |
private |
The flow is entered only by the Continue button closure | Inference: one user-initiated entry point. |
Reference code
AgeAssuranceAndPermissions/ComplianceManager.swift:19 — derived policy over private state
@MainActor
@Observable final class ComplianceManager {
// ...
var requiresParentalConsent: Bool {
regulatoryFeatures.contains(.significantAppChangeRequiresParentalConsent)
}
var requiresAdultNotification: Bool {
regulatoryFeatures.contains(.significantAppChangeRequiresAdultNotification)
}
private var regulatoryFeatures: Set<AgeRangeService.RegulatoryFeature>
// ...
}Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Is the person in a regulated region? | ComplianceManager.identifyRegulatoryRequirements() |
isComplianceRequired is true when any regulatory feature applies (AgeAssuranceAndPermissions/ComplianceManager.swift:38). |
| Which changes still need handling? | SignificantChangeVersion.performFetch() |
Changes whose introducedInVersion is not newer than the original install version are marked handled automatically, with a .numeric string comparison (AgeAssuranceAndPermissions/SignificantChangeVersion.swift:90). |
| Age-range classification | AgeRangeResult.from(_:) |
Upper bound below 18 is a minor; a non-.confirmed declaration is an unverified adult (AgeAssuranceAndPermissions/Helpers.swift:56, AgeAssuranceAndPermissions/Helpers.swift:66). |
| What to do with the result | SignificantChangeView.handleResult(_:) |
Combines classification with the two compliance policies; unverified adults are blocked with phase = .blocked (AgeAssuranceAndPermissions/SignificantChangeView.swift:127). |
| Parental answer handling | AgeAssuranceAndPermissionsApp .task |
An approval marks every change handled; a denial ends the loop and leaves the sheet up (AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:37). |
| Persisting handled changes | SignificantChangeVersion.markAsHandled(_:) |
Writes true per change id and calls synchronize() on the key-value store (AgeAssuranceAndPermissions/SignificantChangeVersion.swift:111). |
Observed: in performFetch(), the inline comment for the first branch says the person “needs to acknowledge,” but that branch adds the change to the set passed to markAsHandled(_:) (AgeAssuranceAndPermissions/SignificantChangeVersion.swift:95, AgeAssuranceAndPermissions/SignificantChangeVersion.swift:102). The code, not the comment, is what this document describes.
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| SwiftUI environment injection | .environment(complianceManager) / @Environment(ComplianceManager.self) (AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:41, AgeAssuranceAndPermissions/SignificantChangeView.swift:14) |
Sheets and nested views share the two managers without parameter threading. |
| Observable state | @MainActor @Observable final class for both managers and the store (AgeAssuranceAndPermissions/ComplianceManager.swift:12) |
SwiftUI re-renders on the properties each body reads. |
| Binding-based state propagation | @Bindable local over the environment object, used for .sheet(isPresented:) (AgeAssuranceAndPermissions/ContentView.swift:15) |
Presentation is driven by model state rather than view state. |
No MVVM, Manager-object, or Repository label is claimed: ComplianceManager and SignificantChangeVersionManager are observable state owners injected through the environment, and the flow decision lives in a view.
Main application flow
sequenceDiagram
participant App as AgeAssuranceAndPermissionsApp
participant CM as ComplianceManager
participant VM as SignificantChangeVersionManager
participant Flow as SignificantChangeView
participant Ask as AskCenter
App->>CM: await identifyRegulatoryRequirements()
App->>VM: await synchronize()
VM-->>Flow: showSignificantChangeView presents sheet
Flow->>Flow: Task { try await requestAgeRange(ageGates:) }
Flow->>VM: handlePendingChanges() for adults
Flow->>Ask: PermissionQuestion for minors
Ask-->>App: for await response in responses(for:)
App->>VM: handleAllChanges() on approval
Reference code
AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift:30 — the parental-answer loop
.task {
await complianceManager.identifyRegulatoryRequirements()
if complianceManager.isComplianceRequired {
await versionManager.synchronize()
for await response in AskCenter.shared.responses(for: SignificantAppUpdateTopic.self) {
guard response.choice.answer == .approval else {
// The parent or guardian denies their minor's request. The minor can no longer use the app.
return
}
// Mark all significant changes as handled.
versionManager.handleAllChanges()
}
}
}AgeAssuranceAndPermissions/SignificantChangeView.swift:73 — the age-range request
private func startFlow() {
phase = .retrieving
Task {
let ageOfMajority = 18
do {
// Presents a dialog asking the person to share their age range.
let response = try await requestAgeRange(ageGates: ageOfMajority)
// Parses the person's response.
let result = AgeRangeResult.from(response)
handleResult(result)
} catch {
flowError = error
showAlert.toggle()
phase = .idle
logger.error("Failed to retrieve age range: \(error.localizedDescription)")
}
}
}AgeAssuranceAndPermissions/SignificantChangeView.swift:110 — minors requiring consent
case .minor(let ageRange):
formattedAgeRange = ageRange
guard complianceManager.requiresParentalConsent else {
versionManager.handlePendingChanges()
dismiss()
return
}
let topic = SignificantAppUpdateTopic(description: versionManager.changesDescription)
parentalQuestion = PermissionQuestion(significantAppUpdateTopic: topic)Naming conventions
- Types:
…Managernames the two environment-injected observable owners;SignificantChangeVersionnames the persistence object, held in a property calledstore. Enums end in their role:…Phase,…Result,…Error. - Methods: verbs describe intent:
identifyRegulatoryRequirements(),synchronize(),fetchLatest(),markAsHandled(_:),handleAllChanges(),handlePendingChanges(),startFlow(),handleResult(_:). - Properties: policies read as questions (
requiresParentalConsent,requiresAdultNotification,isComplianceRequired,hasFetched). - Files: one primary type per file;
Helpers.swiftgroups small enums and extensions.
Architecture takeaways
- Keep regulatory policy (
ComplianceManager) separate from change bookkeeping (SignificantChangeVersionManager); the flow view composes both. - Model significant changes as data with an
introducedInVersion, and compare againstAppTransaction.originalAppVersionso new installs skip changes they never saw. - Parental answers can arrive later and outside the sheet, so the listener lives at app scope in a SwiftUI-managed
.task. hasFetchedand an optionalunhandledChangeskeep the sheet from flashing before the first fetch.- Task lifetimes are implicit: the notification loop and resync tasks are not stored. That is safe here only because their owners live for the whole app.
Source map
| Source file | Relevant symbols |
|---|---|
AgeAssuranceAndPermissions/AgeAssuranceAndPermissionsApp.swift |
AgeAssuranceAndPermissionsApp, .task, AskCenter.shared.responses(for:), logger |
AgeAssuranceAndPermissions/ComplianceManager.swift |
ComplianceManager, identifyRegulatoryRequirements(), requiresParentalConsent, requiresAdultNotification |
AgeAssuranceAndPermissions/SignificantChangeVersionManager.swift |
SignificantChangeVersionManager, synchronize(), handleAllChanges(), handlePendingChanges() |
AgeAssuranceAndPermissions/SignificantChangeVersion.swift |
SignificantChangeVersion, fetchLatest(), performFetch(), markAsHandled(_:), originalAppVersion |
AgeAssuranceAndPermissions/SignificantChange.swift |
SignificantChange, allChanges |
AgeAssuranceAndPermissions/Helpers.swift |
AgeRangeResult.from(_:), SignificantChangePhase, SignificantChangeError |
AgeAssuranceAndPermissions/ContentView.swift |
ContentView, @Bindable sheet binding |
AgeAssuranceAndPermissions/SignificantChangeView.swift |
SignificantChangeView, startFlow(), handleResult(_:), presentSignificantChanges() |
AgeAssuranceAndPermissions/RequestParentalApprovalView.swift |
RequestParentalApprovalView, PermissionButton |
AgeAssuranceAndPermissions/SignificantChangeInformationView.swift |
SignificantChangeInformationView |
AgeAssuranceAndPermissions/ImageView.swift |
ImageView |
AgeAssuranceAndPermissions/MapView.swift |
MapView |
AgeAssuranceAndPermissions/VideoPlayerView.swift |
VideoPlayerView |
AgeAssuranceAndPermissions/AgeAssuranceAndPermissions.entitlements |
Declared Age Range and ubiquity key-value store entitlements |
AgeAssuranceAndPermissions.xcodeproj/project.pbxproj |
SUPPORTS_MACCATALYST, SWIFT_DEFAULT_ACTOR_ISOLATION, deployment target |