Emoji Rangers: Supporting Live Activities, interactivity, and animations
At a glance
| Item | Summary |
|---|---|
| Purpose | Offer Live Activities, controls, animate data updates, and add interactivity to widgets. |
| App architecture | A C/Objective-C header, Swift sample bundle with entry-bearing project variants Emoji Rangers, EmojiRangerWidgetExtension, EmojiRangersWatchApp, each leading to WidgetKit APIs. |
| Main patterns | Model-View-ViewModel, Publisher-backed observable state |
| Project style | 24 scanned source file(s) across C/Objective-C header, Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: async declaration or closure, @MainActor, Sendable or @Sendable, Task; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, ObservableObject, @Published. |
| Key frameworks/packages | SwiftUI, WidgetKit, ActivityKit, Foundation, AppIntents; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── Emoji Rangers/
│ ├── EmojiRangersApp.swift
│ ├── Shared/
│ │ └── Views/
│ │ ├── AdventureLiveActivityView.swift
│ │ └── AvatarView.swift
│ ├── Game Status/
│ │ ├── AdventureView.swift
│ │ └── AdventureViewModel.swift
│ └── ContentView.swift
├── EmojiRangersWatchApp/
│ ├── EmojiRangersWatchApp.swift
│ └── ContentView.swift
├── EmojiRangerWidgetExtension/
│ ├── EmojiRangersWidgetBundle.swift
│ ├── EmojiRangersWidget.swift
│ └── LeaderboardWidget.swift
└── App Intent/
└── EmojiRangerSelection.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: C/Objective-C header, Swift.
- The verified tree contains 11 project/configuration file(s) and 44 source declaration(s).
Overall architecture
flowchart LR
Bundle["Sample bundle"]
V1["Emoji Rangers"]
V2["EmojiRangerWidgetExtension"]
V3["EmojiRangersWatchApp"]
Boundary["WidgetKit APIs"]
Bundle --> V1
V1 --> Boundary
Bundle --> V2
V2 --> Boundary
Bundle --> V3
V3 --> Boundary
Reference code
Emoji Rangers/EmojiRangersApp.swift:10 — architecture anchor
@main
struct EmojiRangersApp: 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
classDiagram
AdventureLiveActivityContent o-- EmojiRanger : hero
AdventureLiveActivityContent *-- Bool : isStale
AdventureLiveActivityContent o-- ContentState : contentState
AdventureLiveActivityView o-- EmojiRanger : hero
Ownership evidence
Emoji Rangers/Shared/Views/AdventureLiveActivityView.swift:14 — stored dependency or nearest verified ownership anchor
#if canImport(ActivityKit)
struct AdventureLiveActivityContent: View {
let hero: EmojiRanger
// ...
}
#endif| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AdventureLiveActivityContent |
EmojiRanger (hero) |
stores or receives | Initialized by the owner; the binding is immutable |
AdventureLiveActivityContent |
Bool (isStale) |
owns value state | Initialized by the owner; the binding is immutable |
AdventureLiveActivityContent |
ContentState (contentState) |
stores or receives | Initialized by the owner; the binding is immutable |
AdventureLiveActivityView |
EmojiRanger (hero) |
stores or receives | Initialized by the owner; the binding is immutable |
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 |
|---|---|---|---|
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | App Intent/EmojiRangerSelection.swift:23 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | Emoji Rangers/Game Status/AdventureView.swift:116 |
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | Emoji Rangers/Game Status/AdventureView.swift:119 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | Emoji Rangers/Game Status/AdventureView.swift:201 |
@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
App Intent/EmojiRangerSelection.swift:23 — representative execution boundary
func results() async throws -> [EmojiRanger] {
EmojiRanger.allHeros
}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 | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | Emoji Rangers/ContentView.swift:12 |
| State propagation | ObservableObject |
ObservableObject supplies an observation contract. | Emoji Rangers/Game Status/AdventureView.swift:117 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | Emoji Rangers/Game Status/AdventureView.swift:153 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | Emoji Rangers/ContentView.swift:7 |
| Source import | WidgetKit |
The cited file imports this module; runtime use and architectural role are not inferred. | App Intent/EmojiRangerSelection.swift:10 |
| Source import | ActivityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Emoji Rangers/Game Status/AdventureView.swift:114 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | App Intent/EmojiRangerSelection.swift:8 |
| Source import | AppIntents |
The cited file imports this module; runtime use and architectural role are not inferred. | App Intent/EmojiRangerSelection.swift:9 |
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
Emoji Rangers/EmojiRangersApp.swift:11 — representative type boundary
@main
struct EmojiRangersApp: App {
// ...
ContentView()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
EmojiRangersApp |
Application entry and top-level composition | App |
EmojiRangersWatchAppApp |
Application entry and top-level composition | App |
AdventureLiveActivityView |
User-interface presentation and input forwarding | View |
LiveActivityAvatarView |
User-interface presentation and input forwarding | View |
EventDescriptionView |
User-interface presentation and input forwarding | View |
OneLineStatsView |
User-interface presentation and input forwarding | View |
TwoLineStatsView |
User-interface presentation and input forwarding | View |
AdventureView |
User-interface presentation and input forwarding | View |
AdventureViewModel |
UI-facing state and feature coordination | ObservableObject |
EmojiRangerOptionsProvider |
Supplies a capability or framework resource | DynamicOptionsProvider |
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 |
|---|---|---|---|
selection (Emoji Rangers/ContentView.swift:12) |
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. |
navigationPath (Emoji Rangers/ContentView.swift:13) |
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. |
currentActivity (Emoji Rangers/Game Status/AdventureView.swift:156) |
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. |
queue (Emoji Rangers/Shared/Mock API/ImageURLProtocol.swift:14) |
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
Emoji Rangers/ContentView.swift:12 — representative boundary
struct ContentView: View {
// ...
@State private var selection: EmojiRanger?
// ...
}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 | EmojiRangersApp, EmojiRangersWatchAppApp |
The source’s App suffix makes this role explicit. |
| Supplies a capability or framework resource | AppIntentProvider, EmojiRangerOptionsProvider, LeaderboardProvider |
The source’s Provider suffix makes this role explicit. |
| User-interface presentation and input forwarding | AdventureLiveActivityView, AdventureView, AllCharactersView, AvatarView |
The source’s View suffix makes this role explicit. |
| UI-facing state and feature coordination | AdventureViewModel |
The source’s ViewModel suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | Emoji Rangers/Game Status/AdventureView.swift:117 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
| Publisher-backed observable state | Emoji Rangers/Game Status/AdventureView.swift:153 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: EmojiRangersApp, EmojiRangersWatchAppApp; Provider: AppIntentProvider, EmojiRangerOptionsProvider, LeaderboardProvider; View: AdventureLiveActivityView, AdventureView, AllCharactersView, AvatarView, ContentView; ViewModel: AdventureViewModel.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
loadAdventure,startAdventureButtonTapped,updateAdventureButtonTapped,endAdventureButtonTapped,endActivity,setup,observeActivity,updateAdventure. - Files:
Emoji Rangers/EmojiRangersApp.swift,Emoji Rangers/Shared/Views/AdventureLiveActivityView.swift,EmojiRangerWidgetExtension/EmojiRangersWidgetBundle.swift,Emoji Rangers/Game Status/AdventureView.swift,App Intent/EmojiRangerSelection.swift,Emoji Rangers/ContentView.swift.
Architecture takeaways
EmojiRangersAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, WidgetKit, ActivityKit, AppIntents 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 |
|---|---|
Emoji Rangers/EmojiRangersApp.swift |
Cited implementation, EmojiRangersApp |
Emoji Rangers/Shared/Views/AdventureLiveActivityView.swift |
Cited implementation, AdventureLiveActivityContent, AdventureLiveActivityView, LiveActivityAvatarView, HealthBar, EventDescriptionView, OneLineStatsView, TwoLineStatsView |
Emoji Rangers/ContentView.swift |
Cited implementation, SwiftUI state property wrapper, SwiftUI, ContentView, TableRow |
Emoji Rangers/Game Status/AdventureView.swift |
Cited implementation, AdventureViewModel, @MainActor, Sendable or @Sendable, Task, ObservableObject, @Published, ActivityKit, AdventureView, ActivityViewState |
Emoji Rangers/Shared/Mock API/ImageURLProtocol.swift |
Cited implementation, ImageURLProtocol, override |
App Intent/EmojiRangerSelection.swift |
async declaration or closure, WidgetKit, Foundation, AppIntents, EmojiRangerSelection, EmojiRangerOptionsProvider, RangerQuery |
EmojiRangersWatchApp/EmojiRangersWatchApp.swift |
EmojiRangersWatchAppApp |
EmojiRangerWidgetExtension/EmojiRangersWidgetBundle.swift |
EmojiRangersWidgetBundle |
Emoji Rangers/Game Status/AdventureViewModel.swift |
Feature implementation |
Emoji Rangers/Shared/Views/AvatarView.swift |
Avatar, AvatarView |
EmojiRangerWidgetExtension/EmojiRangersWidget.swift |
EmojiRangerControl, SimpleEntry, PlaceholderView, EmojiRangerWidgetEntryView, EmojiRangerWidget |
EmojiRangerWidgetExtension/LeaderboardWidget.swift |
LeaderboardProvider, LeaderboardEntry, LeaderboardPlaceholderView, LeaderboardWidgetEntryView, LeaderboardWidget |
EmojiRangersWatchApp/ContentView.swift |
ContentView, TableRow |
Emoji Rangers/Game Status/DetailView.swift |
DetailView |
Emoji Rangers/Shared/Views/AllCharactersView.swift |
AllCharactersView |
Emoji Rangers/Shared/Views/HeroNameView.swift |
HeroNameView |