Drawing content in a group session
At a glance
| Item | Summary |
|---|---|
| Purpose | Invite your friends to draw on a shared canvas while on a FaceTime call. |
| App architecture | A Swift sample with the source-visible chain DrawTogetherApp → ContentView → GroupActivities APIs. |
| Main patterns | Publisher-backed observable state |
| Project style | 11 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, Task, await suspension point; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: ObservableObject, @Published, AnyCancellable. |
| Key frameworks/packages | SwiftUI, Foundation, GroupActivities, PhotosUI, Combine; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── DrawTogether/
│ ├── DrawTogetherApp.swift
│ ├── View/
│ │ ├── CanvasView.swift
│ │ ├── ContentView.swift
│ │ ├── StrokeView.swift
│ │ ├── PhotoPlacementView.swift
│ │ ├── ControlBar.swift
│ │ └── StrokeColorIndicator.swift
│ └── Model/
│ ├── Messages.swift
│ ├── Stroke.swift
│ ├── Canvas.swift
│ └── DrawTogether.swift
└── Configuration/
└── SampleCode.xcconfig
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 4 project/configuration file(s) and 15 source declaration(s).
Overall architecture
flowchart LR
N1["DrawTogetherApp"]
N2["ContentView"]
N3["GroupActivities APIs"]
N1 --> N2
N2 --> N3
Reference code
DrawTogether/DrawTogetherApp.swift:10 — architecture anchor
@main
struct DrawTogetherApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}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 GroupActivities.
Ownership and state
classDiagram
CanvasView o-- Canvas : canvas
ContentView *-- Canvas : canvas
StrokeView o-- Stroke : stroke
PhotoPlacementView *-- CGPoint : location
Ownership evidence
DrawTogether/View/CanvasView.swift:11 — stored dependency or nearest verified ownership anchor
struct CanvasView: View {
@ObservedObject var canvas: Canvas
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
CanvasView |
Canvas (canvas) |
observes externally owned state | The observed object is authoritative |
ContentView |
Canvas (canvas) |
owns wrapper-managed state | App/module collaborators |
StrokeView |
Stroke (stroke) |
observes externally owned state | The observed object is authoritative |
PhotoPlacementView |
CGPoint (location) |
owns wrapper-managed state | Owning lexical scope |
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 |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | DrawTogether/Model/Canvas.swift:19 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | DrawTogether/Model/Canvas.swift:42 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | DrawTogether/Model/Canvas.swift:43 |
@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
DrawTogether/Model/Canvas.swift:19 — representative execution boundary
@MainActor
class Canvas: ObservableObject {
@Published var strokes = [Stroke]()
// ...
}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 | ObservableObject |
ObservableObject supplies an observation contract. | DrawTogether/Model/Canvas.swift:20 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | DrawTogether/Model/Canvas.swift:21 |
| State propagation | AnyCancellable |
A cancellable value records subscription lifetime management. | DrawTogether/Model/Canvas.swift:27 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | DrawTogether/DrawTogetherApp.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | DrawTogether/Model/Canvas.swift:8 |
| Source import | GroupActivities |
The cited file imports this module; runtime use and architectural role are not inferred. | DrawTogether/Model/Canvas.swift:11 |
| Source import | PhotosUI |
The cited file imports this module; runtime use and architectural role are not inferred. | DrawTogether/View/ControlBar.swift:10 |
| Source import | Combine |
The cited file imports this module; runtime use and architectural role are not inferred. | DrawTogether/Model/Canvas.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
DrawTogether/DrawTogetherApp.swift:11 — representative type boundary
@main
struct DrawTogetherApp: App {
// ...
ContentView()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
DrawTogetherApp |
Application entry and top-level composition | App |
CanvasView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
StrokeView |
User-interface presentation and input forwarding | View |
PhotoPlacementView |
User-interface presentation and input forwarding | View |
UpsertStrokeMessage |
Represents a feature value or composable behavior | Codable |
CanvasMessage |
Represents a feature value or composable behavior | Codable |
ImageMetadataMessage |
Represents a feature value or composable behavior | Codable |
Stroke |
Owns feature behavior and collaborator lifecycle | ObservableObject, Identifiable, Codable |
Color |
Defines a closed set of feature states or choices | Int, Codable, CaseIterable |
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 |
|---|---|---|---|
selectedItem (DrawTogether/View/ControlBar.swift:15) |
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. |
location (DrawTogether/View/PhotoPlacementView.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. |
ContentView (DrawTogether/View/ContentView.swift:8) |
implicit internal |
No explicit modifier means the Swift declaration is internal to the module. | Inference: app-target collaboration needs no exported library surface. |
Reference code
DrawTogether/View/ControlBar.swift:15 — representative boundary
struct ControlBar: View {
// ...
@State private var selectedItem: PhotosPickerItem? = nil
// ...
}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 | DrawTogetherApp |
The source’s App suffix makes this role explicit. |
| User-interface presentation and input forwarding | CanvasView, ContentView, PhotoPlacementView, StrokeView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Publisher-backed observable state | DrawTogether/Model/Canvas.swift:22 |
Published properties notify observers while mutation remains with the state object. |
Main application flow
sequenceDiagram
participant Canvas
participant Task
participant messenger
participant journal
Canvas->>Task: Start asynchronous work
Canvas->>messenger: send()
Canvas->>Task: Start asynchronous work
messenger-->>Canvas: messages() stream
Canvas->>Task: Start asynchronous work
messenger-->>Canvas: messages() stream
journal-->>Canvas: images() stream
Canvas->>Canvas: handle()
Reference code
DrawTogether/Model/Canvas.swift:140 — configureGroupSession()
task = Task {
for await (message, _) in messenger.messages(of: CanvasMessage.self) {
handle(message)
}
}Naming conventions
- Types: App: DrawTogetherApp; View: CanvasView, ContentView, PhotoPlacementView, StrokeView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
encode,addPointToActiveStroke,finishStroke,finishImagePlacement,reset,startSharing,configureGroupSession,handle. - Files:
DrawTogether/DrawTogetherApp.swift,DrawTogether/View/CanvasView.swift,DrawTogether/View/ContentView.swift,DrawTogether/View/StrokeView.swift,DrawTogether/View/PhotoPlacementView.swift,DrawTogether/Model/Stroke.swift.
Architecture takeaways
DrawTogetherAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, GroupActivities, PhotosUI 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 |
|---|---|
DrawTogether/DrawTogetherApp.swift |
Cited implementation, DrawTogetherApp, SwiftUI |
DrawTogether/View/CanvasView.swift |
Cited implementation, CanvasView, CanvasView_Previews |
DrawTogether/View/ControlBar.swift |
Cited implementation, PhotosUI, ControlBar, ControlBar_Previews |
DrawTogether/View/PhotoPlacementView.swift |
Cited implementation, PhotoPlacementView |
DrawTogether/View/ContentView.swift |
ContentView, ContentView_Previews |
DrawTogether/Model/Canvas.swift |
Cited implementation, @MainActor, Task, await suspension point, ObservableObject, @Published, AnyCancellable, Foundation, GroupActivities, Combine, CanvasImage, Canvas |
DrawTogether/View/StrokeView.swift |
StrokeView, StrokeView_Previews |
DrawTogether/Model/Messages.swift |
UpsertStrokeMessage, CanvasMessage, ImageMetadataMessage |
DrawTogether/Model/Stroke.swift |
Stroke, CodingKeys, Color |
DrawTogether/View/StrokeColorIndicator.swift |
StrokeColorIndicator, StrokeColorIndicator_Previews |
DrawTogether/Model/DrawTogether.swift |
DrawTogether |