ShazamKit Dance Finder with Managed Session
At a glance
| Item | Summary |
|---|---|
| Purpose | Find a video of dance moves for a specific song by matching the audio to a custom catalog, and show a history of recognized songs. |
| App architecture | A Swift sample with the source-visible chain ShazamKitDanceFinderApp → ContentView → NowPlayingViewModel → ResourcesProvider → ShazamKit APIs. |
| Main patterns | Model-View-ViewModel, Delegate or data-source callbacks, Coordinator, SwiftUI environment injection, Publisher-backed observable state |
| Project style | 17 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, async declaration or closure, Task closure isolated to MainActor, Task, Task.detached; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: ObservableObject, @Published, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, ShazamKit, Foundation, AVKit; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── Shared Source/
│ ├── App/
│ │ ├── ShazamKitDanceFinderApp.swift
│ │ └── ContentView.swift
│ ├── Data/
│ │ ├── NowPlayingViewModel.swift
│ │ └── ResourcesProvider.swift
│ └── Views/
│ ├── DanceCompletionView.swift
│ ├── NowPlayingView.swift
│ ├── RecentDanceRowView.swift
│ └── VideoPlayerView.swift
├── Part 1 - Matching Audio/
│ └── ShazamKitDanceFinder/
│ ├── RecentDancesView.swift
│ └── Matcher.swift
├── Part 2 - Matching Audio with SHManagedSession/
│ └── ShazamKitDanceFinder/
│ └── RecentDancesView.swift
└── Part 3 - Final/
└── ShazamKitDanceFinder/
└── RecentDancesView.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 11 project/configuration file(s) and 31 source declaration(s).
Overall architecture
flowchart LR
N1["ShazamKitDanceFinderApp"]
N2["ContentView"]
N3["NowPlayingViewModel"]
N4["ResourcesProvider"]
N5["ShazamKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
Shared Source/App/ShazamKitDanceFinderApp.swift:10 — architecture anchor
@main
struct ShazamKitDanceFinderApp: App {
@StateObject private var matcher = Matcher()
@StateObject private var sceneHandler = SceneHandler()
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(matcher)
.environmentObject(sceneHandler)
.onChange(of: scenePhase) { _, newScenePhase in
sceneHandler.sceneChanged(to: newScenePhase)
}
}
}
}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 ShazamKit.
Ownership and state
classDiagram
RecentDancesView *-- String : emptyStateImageName
RecentDancesView *-- String : emptyStateTextTitle
RecentDancesView *-- String : emptyStateTextSubtitle
RecentDancesView *-- Double : deleteSwipeViewOpacity
Ownership evidence
Part 1 - Matching Audio/ShazamKitDanceFinder/RecentDancesView.swift:20 — stored dependency or nearest verified ownership anchor
private enum ViewConstants {
static let emptyStateImageName: String = "EmptyStateIcon"
static let emptyStateTextTitle: String = "No Dances Yet?"
static let emptyStateTextSubtitle: String = "Find some music to start learning"
static let deleteSwipeViewOpacity: Double = 0.5
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
RecentDancesView |
String (emptyStateImageName) |
owns value state | Initialized by the owner; the binding is immutable |
RecentDancesView |
String (emptyStateTextTitle) |
owns value state | Initialized by the owner; the binding is immutable |
RecentDancesView |
String (emptyStateTextSubtitle) |
owns value state | Initialized by the owner; the binding is immutable |
RecentDancesView |
Double (deleteSwipeViewOpacity) |
owns value state | 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 |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:16 |
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:39 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:60 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:60 |
| Detached task | Task.detached |
The source creates a detached task; no specific operating-system thread is established. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:77 |
@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
Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:16 — representative execution boundary
@MainActor final class Matcher: ObservableObject {
// ...
@Published var isMatching = false
// ...
}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. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:16 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:18 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | Part 1 - Matching Audio/ShazamKitDanceFinder/RecentDancesView.swift:45 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | Part 1 - Matching Audio/ShazamKitDanceFinder/RecentDancesView.swift:8 |
| Source import | ShazamKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:8 |
| Source import | AVKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Shared Source/Data/NowPlayingViewModel.swift:8 |
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
Shared Source/App/ShazamKitDanceFinderApp.swift:11 — representative type boundary
@main
struct ShazamKitDanceFinderApp: App {
// ...
@StateObject private var matcher = Matcher()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
ShazamKitDanceFinderApp |
Application entry and top-level composition | App |
SceneHandler |
Handles callbacks or feature events | ObservableObject |
NowPlayingViewModel |
UI-facing state and feature coordination | ObservableObject |
RecentDancesView |
User-interface presentation and input forwarding | View |
RecentDancesView |
User-interface presentation and input forwarding | View |
RecentDancesView |
User-interface presentation and input forwarding | View |
DanceCompletionView |
User-interface presentation and input forwarding | View |
NowPlayingView |
User-interface presentation and input forwarding | View |
RecentDanceRowView |
User-interface presentation and input forwarding | View |
ContentView |
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 |
|---|---|---|---|
session (Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:25) |
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. |
audioEngine (Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:26) |
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. |
configureAudioEngine (Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:74) |
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. |
isListEmpty (Part 1 - Matching Audio/ShazamKitDanceFinder/RecentDancesView.swift:41) |
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
Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:25 — representative boundary
@MainActor final class Matcher: ObservableObject {
// ...
private let session: SHSession
// ...
}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 | ShazamKitDanceFinderApp |
The source’s App suffix makes this role explicit. |
| Cross-object flow or session coordination | Coordinator |
The source’s Coordinator suffix makes this role explicit. |
| Handles callbacks or feature events | SceneHandler |
The source’s Handler suffix makes this role explicit. |
| Supplies a capability or framework resource | ResourcesProvider |
The source’s Provider suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, DanceCompletionView, NowPlayingView, RecentDanceRowView |
The source’s View suffix makes this role explicit. |
| UI-facing state and feature coordination | NowPlayingViewModel |
The source’s ViewModel suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | Shared Source/Data/NowPlayingViewModel.swift:11 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
| Delegate or data-source callbacks | Shared Source/Views/VideoPlayerView.swift:14 |
Callback protocols invert event delivery back into the sample’s owner. |
| Coordinator | Shared Source/Views/VideoPlayerView.swift:14 |
A role-named coordinator centralizes cross-object flow. |
| SwiftUI environment injection | Part 1 - Matching Audio/ShazamKitDanceFinder/RecentDancesView.swift:51 |
The environment supplies state or a capability without threading it through every initializer. |
| Publisher-backed observable state | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:19 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: ShazamKitDanceFinderApp; Coordinator: Coordinator; Handler: SceneHandler; Provider: ResourcesProvider; View: ContentView, DanceCompletionView, NowPlayingView, RecentDanceRowView, RecentDancesView; ViewModel: NowPlayingViewModel.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
sceneChanged,setupPlayback,stopPlayback,addMediaItem,viewMovedToForeground,viewMovedToBackground,updateNowPlayingViewVisibility,hideNowPlayingView. - Files:
Shared Source/App/ShazamKitDanceFinderApp.swift,Shared Source/Data/NowPlayingViewModel.swift,Part 1 - Matching Audio/ShazamKitDanceFinder/RecentDancesView.swift,Part 2 - Matching Audio with SHManagedSession/ShazamKitDanceFinder/RecentDancesView.swift,Part 3 - Final/ShazamKitDanceFinder/RecentDancesView.swift,Shared Source/Views/DanceCompletionView.swift.
Architecture takeaways
ShazamKitDanceFinderAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, ShazamKit, AVKit 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 |
|---|---|
Shared Source/App/ShazamKitDanceFinderApp.swift |
Cited implementation, ShazamKitDanceFinderApp, SceneHandler, State |
Part 1 - Matching Audio/ShazamKitDanceFinder/RecentDancesView.swift |
Cited implementation, SwiftUI state property wrapper, SwiftUI, NavigationPath, RecentDancesView, ViewConstants, RecentDancesView_Previews |
Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift |
Cited implementation, @MainActor, async declaration or closure, Task closure isolated to MainActor, Task, Task.detached, ObservableObject, @Published, ShazamKit, Foundation, MatchResult, Matcher |
Shared Source/Data/NowPlayingViewModel.swift |
NowPlayingViewModel, AVKit, Constants |
Shared Source/Views/VideoPlayerView.swift |
Cited implementation, Coordinator, VideoPlayerView |
Part 2 - Matching Audio with SHManagedSession/ShazamKitDanceFinder/RecentDancesView.swift |
NavigationPath, RecentDancesView, ViewConstants, RecentDancesView_Previews |
Part 3 - Final/ShazamKitDanceFinder/RecentDancesView.swift |
NavigationPath, RecentDancesView, ViewConstants, RecentDancesView_Previews |
Shared Source/Views/DanceCompletionView.swift |
DanceCompletionView, ViewConstants, DanceCompletionView_Previews |
Shared Source/Views/NowPlayingView.swift |
NowPlayingView, ViewConstants, NowPlayingView_Previews |
Shared Source/Views/RecentDanceRowView.swift |
RecentDanceRowView, ViewConstants, RecentDanceRowView_Previews |
Shared Source/App/ContentView.swift |
ContentView, ContentView_Previews |
Shared Source/Data/ResourcesProvider.swift |
ResourcesProvider |
Part 2 - Matching Audio with SHManagedSession/ShazamKitDanceFinder/Matcher.swift |
MatchResult, Matcher |
Part 3 - Final/ShazamKitDanceFinder/Matcher.swift |
MatchResult, Matcher |
Shared Source/Views/CurvedTopSideRectangle.swift |
CurvedTopSideRectangle |
Shared Source/Extensions/Color.swift |
Feature implementation |