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, Actor-isolated state |
| Project style | 17 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
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 {
// ...
}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
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
static let matchingStateTextTopPadding: CGFloat = 24
static let matchingStateTextBottomPadding: CGFloat = 16
static let progressViewScaleEffect: CGFloat = 1.1| 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.
Class and protocol design
Shared Source/App/ShazamKitDanceFinderApp.swift:11 — representative type boundary
struct ShazamKitDanceFinderApp: App {
// ...
}| 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. |
| Actor-isolated state | Part 1 - Matching Audio/ShazamKitDanceFinder/Matcher.swift:16 |
Actor annotations make the concurrency ownership boundary explicit. |
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 |
ShazamKitDanceFinderApp, SceneHandler, State |
Shared Source/Data/NowPlayingViewModel.swift |
NowPlayingViewModel, Constants |
Part 1 - Matching Audio/ShazamKitDanceFinder/RecentDancesView.swift |
NavigationPath, RecentDancesView, ViewConstants, RecentDancesView_Previews |
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/Views/VideoPlayerView.swift |
VideoPlayerView, Coordinator |