Sample CodeiOS, iPadOSReviewed 2026-07-21View on Apple Developer

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 DrawTogetherAppContentViewGroupActivities APIs.
Main patterns Publisher-backed observable state, Actor-isolated state
Project style 11 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

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

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

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.

Class and protocol design

DrawTogether/DrawTogetherApp.swift:11 — representative type boundary

struct DrawTogetherApp: App {
    var body: some Scene {
        WindowGroup {
            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.
Actor-isolated state DrawTogether/Model/Canvas.swift:19 Actor annotations make the concurrency ownership boundary explicit.

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

  • DrawTogetherApp is 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 DrawTogetherApp
DrawTogether/View/CanvasView.swift CanvasView, CanvasView_Previews
DrawTogether/View/ContentView.swift ContentView, ContentView_Previews
DrawTogether/View/StrokeView.swift StrokeView, StrokeView_Previews
DrawTogether/View/PhotoPlacementView.swift PhotoPlacementView
DrawTogether/Model/Messages.swift UpsertStrokeMessage, CanvasMessage, ImageMetadataMessage
DrawTogether/Model/Stroke.swift Stroke, CodingKeys, Color
DrawTogether/Model/Canvas.swift CanvasImage, Canvas
DrawTogether/View/ControlBar.swift ControlBar, ControlBar_Previews
DrawTogether/View/StrokeColorIndicator.swift StrokeColorIndicator, StrokeColorIndicator_Previews