Building an App to Notify Users of COVID-19 Exposure
At a glance
| Item | Summary |
|---|---|
| Purpose | Inform people when they may have been exposed to COVID-19. |
| App architecture | A Swift sample bundle with entry-bearing project variants ExposureNotificationApp-iOS12, ExposureNotificationApp, each leading to ExposureNotification APIs. |
| Main patterns | View-controller organization, Delegate or data-source callbacks, Central store |
| Project style | 33 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: DispatchQueue.main.async; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: NotificationCenter. |
| Key frameworks/packages | UIKit, ExposureNotification, Foundation, BackgroundTasks, UserNotifications; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── ExposureNotificationApp-iOS12/
│ └── AppDelegate.swift
├── ExposureNotificationApp/
│ ├── Custom View Controllers/
│ │ ├── ExposureDetailsViewController.swift
│ │ ├── OnboardingViewController.swift
│ │ ├── StepViewController.swift
│ │ ├── TestVerificationViewController.swift
│ │ ├── ExposureNotificationsInfoViewController.swift
│ │ ├── ExposuresViewController.swift
│ │ ├── NotifyOthersViewController.swift
│ │ └── TestResultDetailsViewController.swift
│ └── Developer/
│ ├── DeveloperDiagnosisKeysViewController.swift
│ └── DeveloperViewController.swift
└── Common/
└── Model/
└── LocalStore.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 17 project/configuration file(s) and 101 source declaration(s).
Overall architecture
flowchart LR
Bundle["Sample bundle"]
V1["ExposureNotificationApp-iOS12"]
V2["ExposureNotificationApp"]
Boundary["ExposureNotification APIs"]
Bundle --> V1
V1 --> Boundary
Bundle --> V2
V2 --> Boundary
Reference code
ExposureNotificationApp-iOS12/AppDelegate.swift:12 — architecture anchor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
/// iOS 13 and later use the `window` property from the scene delegate, but this is needed for the
/// storyboard to function correctly on iOS 12.5.
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
}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
classDiagram
AppDelegate o-- UIWindow : window
ExposureDetailsViewController o-- RelativeDateTimeFormatter : relativeDateFormatter
ExposureDetailsCell o-- UILabel : headerLabel
ExposureDetailsCell o-- UILabel : diagnosisVerificationLabel
Ownership evidence
ExposureNotificationApp-iOS12/AppDelegate.swift:17 — stored dependency or nearest verified ownership anchor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AppDelegate |
UIWindow (window) |
stores or receives | App/module collaborators |
ExposureDetailsViewController |
RelativeDateTimeFormatter (relativeDateFormatter) |
stores or receives | Initialized by the owner; the binding is immutable |
ExposureDetailsCell |
UILabel (headerLabel) |
stores or receives | App/module collaborators |
ExposureDetailsCell |
UILabel (diagnosisVerificationLabel) |
stores or receives | App/module collaborators |
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.
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 |
|---|---|---|---|
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | Common/Model/ExposureManager.swift:242 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
Common/Model/ExposureManager.swift:242 — representative execution boundary
DispatchQueue.main.async {
if let error = error {
print("Error showing error user notification: \(error)")
}
}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 |
|---|---|---|---|
| State propagation | NotificationCenter |
NotificationCenter distributes named process-local events. | Common/Model/LocalStore.swift:51 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Common/Utilities.swift:8 |
| Source import | ExposureNotification |
The cited file imports this module; runtime use and architectural role are not inferred. | Common/BackgroundTasks.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Common/BackgroundTasks.swift:8 |
| Source import | BackgroundTasks |
The cited file imports this module; runtime use and architectural role are not inferred. | Common/BackgroundTasks.swift:10 |
| Source import | UserNotifications |
The cited file imports this module; runtime use and architectural role are not inferred. | Common/Model/ExposureManager.swift:10 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | ExposureNotificationApp/Developer/DeveloperDiagnosisKeysViewController.swift:10 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
ExposureNotificationApp-iOS12/AppDelegate.swift:13 — representative type boundary
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate |
ExposureDetailsViewController |
View lifecycle, callbacks, and feature coordination | ValueStepViewController<Exposure, ExposureDetailsViewController.CustomItem> |
ExposureLearnMoreViewController |
View lifecycle, callbacks, and feature coordination | StepViewController |
OnboardingViewController |
View lifecycle, callbacks, and feature coordination | StepNavigationController |
WelcomeViewController |
View lifecycle, callbacks, and feature coordination | StepViewController |
EnableExposureNotificationsViewController |
View lifecycle, callbacks, and feature coordination | StepViewController |
RecommendExposureNotificationsViewController |
View lifecycle, callbacks, and feature coordination | StepViewController |
RecommendExposureNotificationsSettingsViewController |
View lifecycle, callbacks, and feature coordination | StepViewController |
RecommendPushNotificationsViewController |
View lifecycle, callbacks, and feature coordination | StepViewController |
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 |
|---|---|---|---|
segueRowData (ExposureNotificationApp-iOS12/View Controllers/MainViewController.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. |
sectionTitles (ExposureNotificationApp-iOS12/View Controllers/MainViewControllerData.swift:49) |
fileprivate |
Use is restricted to this source file. | Inference: share with same-file helpers or extensions without exposing the symbol module-wide. |
statusSections (ExposureNotificationApp-iOS12/View Controllers/MainViewControllerData.swift:74) |
fileprivate |
Use is restricted to this source file. | Inference: share with same-file helpers or extensions without exposing the symbol module-wide. |
shareSections (ExposureNotificationApp-iOS12/View Controllers/MainViewControllerData.swift:122) |
fileprivate |
Use is restricted to this source file. | Inference: share with same-file helpers or extensions without exposing the symbol module-wide. |
Reference code
ExposureNotificationApp-iOS12/View Controllers/MainViewController.swift:16 — representative boundary
class MainViewController: UITableViewController {
// ...
private var segueRowData: TableRowData?
// ...
}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 |
|---|---|---|
| View lifecycle, callbacks, and feature coordination | AboutTestIdentifiersViewController, BeforeYouGetStartedViewController, ContentViewController, CustomStepViewController |
The source’s Controller suffix makes this role explicit. |
| Supplies data through a callback contract | DataSource |
The source’s DataSource suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate, SceneDelegate |
The source’s Delegate suffix makes this role explicit. |
| Long-lived feature or framework coordination | ExposureManager |
The source’s Manager suffix makes this role explicit. |
| Centralized state or persistence access | LocalStore |
The source’s Store suffix makes this role explicit. |
| User-interface presentation and input forwarding | DeveloperQRCodeScannerView, EntryStackView, EntryView, RequirementView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | ExposureNotificationApp/Custom View Controllers/TestVerificationViewController.swift:146 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Delegate or data-source callbacks | ExposureNotificationApp-iOS12/AppDelegate.swift:13 |
Callback protocols invert event delivery back into the sample’s owner. |
| Central store | Common/Model/LocalStore.swift:63 |
A store-named type centralizes feature state or persistence. |
Naming conventions
- Types: Controller: AboutTestIdentifiersViewController, BeforeYouGetStartedViewController, ContentViewController, CustomStepViewController, DeveloperDiagnosisKeysViewController; DataSource: DataSource; Delegate: AppDelegate, SceneDelegate; Manager: ExposureManager; Store: LocalStore; View: DeveloperQRCodeScannerView, EntryStackView, EntryView, RequirementView, TableHeaderView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
application,viewDidLoad,tableView,modifySnapshot,learnMore,enableExposureNotifications,enablePushNotifications,viewDidAppear. - Files:
ExposureNotificationApp-iOS12/AppDelegate.swift,ExposureNotificationApp/Custom View Controllers/ExposureDetailsViewController.swift,ExposureNotificationApp/Custom View Controllers/OnboardingViewController.swift,ExposureNotificationApp/Custom View Controllers/StepViewController.swift,ExposureNotificationApp/Custom View Controllers/TestVerificationViewController.swift,ExposureNotificationApp/Developer/DeveloperDiagnosisKeysViewController.swift.
Architecture takeaways
AppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches UIKit, ExposureNotification, BackgroundTasks, UserNotifications 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 |
|---|---|
ExposureNotificationApp-iOS12/AppDelegate.swift |
Cited implementation, AppDelegate |
ExposureNotificationApp-iOS12/View Controllers/MainViewController.swift |
Cited implementation, MainViewController |
ExposureNotificationApp-iOS12/View Controllers/MainViewControllerData.swift |
Cited implementation, TableViewSections, TableRowData |
ExposureNotificationApp/Custom View Controllers/TestVerificationViewController.swift |
AboutTestIdentifiersViewController, TestVerificationViewController, TestStepViewController, BeforeYouGetStartedViewController, TestIdentifierViewController, TestAdministrationDateViewController, CustomItem, ReviewViewController, FinishedViewController, TestAdministrationDatePickerCell |
Common/Model/LocalStore.swift |
LocalStore, NotificationCenter, Exposure, TestResult, Persisted |
Common/Model/ExposureManager.swift |
DispatchQueue.main.async, UserNotifications, ExposureManager |
Common/Utilities.swift |
UIKit, SupportedENAPIVersion |
Common/BackgroundTasks.swift |
ExposureNotification, Foundation, BackgroundTasks, Feature implementation |
ExposureNotificationApp/Developer/DeveloperDiagnosisKeysViewController.swift |
AVFoundation, DeveloperDiagnosisKeysViewController, Section, Item, DataSource, DeveloperQRCodeViewController, DeveloperQRCodeScannerViewController, DeveloperQRCodeScannerView |
ExposureNotificationApp/Custom View Controllers/ExposureDetailsViewController.swift |
ExposureDetailsViewController, CustomItem, ExposureDetailsCell, ExposureNextStepsCell, ExposureFootnoteCell, ExposureLearnMoreViewController |
ExposureNotificationApp/Custom View Controllers/OnboardingViewController.swift |
OnboardingViewController, WelcomeViewController, EnableExposureNotificationsViewController, RecommendExposureNotificationsViewController, RecommendExposureNotificationsSettingsViewController, RecommendPushNotificationsViewController, NotifyingOthersViewController |
ExposureNotificationApp/Custom View Controllers/StepViewController.swift |
Step, BarButton, Button, StepNavigationController, CustomStepViewController, Section, Item, StepViewController, StepOptionalSeparatorCell, StepTitleCell, StepTextCell, ValueStepViewController |
ExposureNotificationApp/Custom View Controllers/ExposureNotificationsInfoViewController.swift |
ExposureNotificationsInfoViewController, ContentViewController, ExposureNotificationsPrivacyViewController |
ExposureNotificationApp/Custom View Controllers/ExposuresViewController.swift |
ExposuresViewController, Section, Item, DataSource |
ExposureNotificationApp/Custom View Controllers/NotifyOthersViewController.swift |
NotifyOthersViewController, Section, Item, DataSource |
ExposureNotificationApp/Custom View Controllers/TestResultDetailsViewController.swift |
TestResultDetailsViewController, Section, Item, DataSource |