Building a guessing game for visionOS
At a glance
| Item | Summary |
|---|---|
| Purpose | Create a team-based guessing game for visionOS using Group Activities. |
| App architecture | A Swift sample with the source-visible chain GuessTogetherApp → SessionController → PhraseManager → GroupActivities APIs. |
| Main patterns | View-controller organization, Central store |
| Project style | 25 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: Sendable or @Sendable, Task, await suspension point, @MainActor, Task.detached; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, GroupActivities, Spatial, Foundation, CoreTransferable; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── GuessTogether/
├── GuessTogetherApp.swift
├── Models/
│ ├── GameModel.swift
│ ├── PlayerModel.swift
│ └── AppModel.swift
├── ImmersiveSpace/
│ ├── PhraseDeckView.swift
│ ├── PhraseDeckPodiumView.swift
│ └── SeatScoresView.swift
├── Utilities/
│ └── PhraseManager.swift
├── WindowViews/
│ ├── GameScoreBoardView.swift
│ ├── TeamSelectionView.swift
│ └── WelcomeView.swift
└── GroupActivity/
└── SessionController.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 37 source declaration(s).
Overall architecture
flowchart LR
N1["GuessTogetherApp"]
N2["SessionController"]
N3["PhraseManager"]
N4["GroupActivities APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
GuessTogether/GuessTogetherApp.swift:10 — architecture anchor
@main
struct GuessTogetherApp: App {
@State var appModel = AppModel()
var body: some Scene {
Group {
GuessTogetherWindow()
GameSpace()
}
.environment(appModel)
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Group Activities.
Ownership and state
classDiagram
GuessTogetherApp *-- AppModel : appModel
GameModel o-- ActivityStage : stage
GameModel o-- Excludedcategories : excludedCategories
GameModel *-- Array : turnHistory
Ownership evidence
GuessTogether/GuessTogetherApp.swift:12 — stored dependency or nearest verified ownership anchor
@main
struct GuessTogetherApp: App {
@State var appModel = AppModel()
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
GuessTogetherApp |
AppModel (appModel) |
owns wrapper-managed state | App/module collaborators |
GameModel |
ActivityStage (stage) |
stores or receives | App/module collaborators |
GameModel |
Excludedcategories (excludedCategories) |
stores or receives | App/module collaborators |
GameModel |
Array (turnHistory) |
owns value state | 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 |
|---|---|---|---|
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | GuessTogether/GroupActivity/GuessTogetherActivity.swift:11 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | GuessTogether/GroupActivity/SessionController+RemoteParticipantSynchronization.swift:12 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | GuessTogether/GroupActivity/SessionController+RemoteParticipantSynchronization.swift:15 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | GuessTogether/GroupActivity/SessionController.swift:11 |
| Detached task | Task.detached |
The source creates a detached task; no specific operating-system thread is established. | GuessTogether/WindowViews/Shared/SharePlayButton.swift:42 |
@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
GuessTogether/GroupActivity/GuessTogetherActivity.swift:11 — representative execution boundary
struct GuessTogetherActivity: GroupActivity, Transferable, Sendable {
var metadata: GroupActivityMetadata = {
var metadata = GroupActivityMetadata()
metadata.title = "Guess Together"
return metadata
}()
}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 | @Observable |
Observation macro publishes source-visible changes. | GuessTogether/GroupActivity/SessionController.swift:11 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | GuessTogether/GuessTogetherApp.swift:12 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | GuessTogether/GuessTogetherApp.swift:8 |
| Source import | GroupActivities |
The cited file imports this module; runtime use and architectural role are not inferred. | GuessTogether/GroupActivity/GuessTogetherActivity.swift:9 |
| Source import | Spatial |
The cited file imports this module; runtime use and architectural role are not inferred. | GuessTogether/ImmersiveSpace/PhraseDeckPodiumView.swift:10 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | GuessTogether/GroupActivity/SessionController+PlayerOrder.swift:8 |
| Source import | CoreTransferable |
The cited file imports this module; runtime use and architectural role are not inferred. | GuessTogether/GroupActivity/GuessTogetherActivity.swift:8 |
| Source import | Observation |
The cited file imports this module; runtime use and architectural role are not inferred. | GuessTogether/GroupActivity/SessionController.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
GuessTogether/GuessTogetherApp.swift:11 — representative type boundary
@main
struct GuessTogetherApp: App {
@State var appModel = AppModel()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
GuessTogetherApp |
Application entry and top-level composition | App |
GameModel |
Feature data or observable state | Codable, Hashable, Sendable |
PhraseDeckView |
User-interface presentation and input forwarding | View |
PhraseCardView |
User-interface presentation and input forwarding | View |
PlayerModel |
Feature data or observable state | Codable, Hashable, Sendable, Identifiable |
AppModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
PhraseManager |
Long-lived feature or framework coordination | Sendable |
ScoreBoardView |
User-interface presentation and input forwarding | View |
TeamStatusView |
User-interface presentation and input forwarding | View |
TeamSelectionView |
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 |
|---|---|---|---|
observeRemoteGameModelUpdates (GuessTogether/GroupActivity/SessionController+RemoteParticipantSynchronization.swift:46) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
observeRemotePlayerModelUpdates (GuessTogether/GroupActivity/SessionController+RemoteParticipantSynchronization.swift:76) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
observeActiveRemoteParticipants (GuessTogether/GroupActivity/SessionController+RemoteParticipantSynchronization.swift:84) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
phrases (GuessTogether/Utilities/PhraseManager.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. |
Reference code
GuessTogether/GroupActivity/SessionController+RemoteParticipantSynchronization.swift:46 — representative boundary
private func observeRemoteGameModelUpdates() {
// ...
let senderID = context.source.id
// ...
}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 | GuessTogetherApp |
The source’s App suffix makes this role explicit. |
| View lifecycle, callbacks, and feature coordination | SessionController |
The source’s Controller suffix makes this role explicit. |
| Long-lived feature or framework coordination | PhraseManager |
The source’s Manager suffix makes this role explicit. |
| Feature data or observable state | AppModel, GameModel, PlayerModel |
The source’s Model suffix makes this role explicit. |
| Centralized state or persistence access | GameSyncStore |
The source’s Store suffix makes this role explicit. |
| User-interface presentation and input forwarding | ActivitySharingView, CategorySelectionView, MainView, PhraseCardView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | GuessTogether/GroupActivity/SessionController.swift:12 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Central store | GuessTogether/GroupActivity/SessionController+RemoteParticipantSynchronization.swift:130 |
A store-named type centralizes feature state or persistence. |
Main application flow
sequenceDiagram
participant MainView
participant GuessTogetherActivity
participant SessionController
participant Task
GuessTogetherActivity-->>MainView: session() stream
MainView->>SessionController: SessionController()
MainView->>Task: Start asynchronous work
MainView-->>MainView: state() stream
Reference code
GuessTogether/WindowViews/MainView.swift:63 — observeGroupSessions()
@Sendable
func observeGroupSessions() async {
for await session in GuessTogetherActivity.sessions() {
let sessionController = await SessionController(session, appModel: appModel)
guard let sessionController else {
continue
}
appModel.sessionController = sessionController
// Create a task to observe the group session state and clear the
// session controller when the group session invalidates.
Task {
for await state in session.$state.values {
guard appModel.sessionController?.session.id == session.id else {
return
}
if case .invalidated = state {
appModel.sessionController = nil
return
}
}
}
}
}Naming conventions
- Types: App: GuessTogetherApp; Controller: SessionController; Manager: PhraseManager; Model: AppModel, GameModel, PlayerModel; Store: GameSyncStore; View: ActivitySharingView, CategorySelectionView, MainView, PhraseCardView, PhraseDeckPodiumView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
randomPhrase,teamHasPlayers,playersOnTeam. - Files:
GuessTogether/GuessTogetherApp.swift,GuessTogether/Models/GameModel.swift,GuessTogether/ImmersiveSpace/PhraseDeckView.swift,GuessTogether/Models/PlayerModel.swift,GuessTogether/Models/AppModel.swift,GuessTogether/Utilities/PhraseManager.swift.
Architecture takeaways
GuessTogetherAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, GroupActivities, Spatial, CoreTransferable 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 |
|---|---|
GuessTogether/GuessTogetherApp.swift |
Cited implementation, GuessTogetherApp, SwiftUI state property wrapper, SwiftUI |
GuessTogether/GroupActivity/SessionController+RemoteParticipantSynchronization.swift |
Cited implementation, GameSyncStore, Task, await suspension point, GameMessage |
GuessTogether/Utilities/PhraseManager.swift |
Cited implementation, PhraseManager, Phrase |
GuessTogether/GroupActivity/SessionController.swift |
SessionController, @MainActor, @Observable, Observation |
GuessTogether/GroupActivity/GuessTogetherActivity.swift |
Sendable or @Sendable, GroupActivities, CoreTransferable, GuessTogetherActivity |
GuessTogether/WindowViews/Shared/SharePlayButton.swift |
Task.detached, SharePlayButton, ActivitySharingView |
GuessTogether/ImmersiveSpace/PhraseDeckPodiumView.swift |
Spatial, PhraseDeckPodiumView |
GuessTogether/GroupActivity/SessionController+PlayerOrder.swift |
Foundation, Feature implementation |
GuessTogether/Models/GameModel.swift |
GameModel, GameStage, ActivityStage |
GuessTogether/ImmersiveSpace/PhraseDeckView.swift |
PhraseDeckView, PhraseDeckButton, Kind, PhraseCardView |
GuessTogether/Models/PlayerModel.swift |
PlayerModel, Team |
GuessTogether/Models/AppModel.swift |
AppModel |
GuessTogether/WindowViews/GameScoreBoardView.swift |
ScoreBoardView, TeamStatusView |
GuessTogether/WindowViews/TeamSelectionView.swift |
TeamSelectionView, TeamList |
GuessTogether/WindowViews/WelcomeView.swift |
WelcomeView, WelcomeBanner |
GuessTogether/ImmersiveSpace/SeatScoresView.swift |
SeatScoresView |
GuessTogether/WindowViews/MainView.swift |
observeGroupSessions |