Bringing Photos picker to your SwiftUI app
At a glance
| Item | Summary |
|---|---|
| Purpose | Select media assets by using a Photos picker view that SwiftUI provides. |
| App architecture | A Swift sample with the source-visible chain PhotosPickerExampleApp → ProfileModel → PhotosUI APIs. |
| Main patterns | Publisher-backed observable state |
| Project style | 4 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, DispatchQueue.main.async; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, ObservableObject, @Published. |
| Key frameworks/packages | SwiftUI, PhotosUI, CoreTransferable; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── PhotosPickerDemo/
│ ├── PhotosPickerExampleApp.swift
│ ├── ProfileModel.swift
│ ├── ProfileImage.swift
│ ├── Profile.swift
│ └── Supporting Files/
│ └── PhotosPickerDemo.entitlements
├── Configuration/
│ └── SampleCode.xcconfig
└── PhotosPickerDemo.xcodeproj/
├── .xcodesamplecode.plist
└── project.pbxproj
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 10 source declaration(s).
Overall architecture
flowchart LR
N1["PhotosPickerExampleApp"]
N2["ProfileModel"]
N3["PhotosUI APIs"]
N1 --> N2
N2 --> N3
Reference code
PhotosPickerDemo/PhotosPickerExampleApp.swift:10 — architecture anchor
@main
struct PhotosPickerDemoApp: App {
var body: some Scene {
WindowGroup {
Profile()
}
}
}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 PhotosUI.
Ownership and state
classDiagram
ProfileModel *-- String : firstName
ProfileModel *-- String : lastName
ProfileModel *-- String : aboutMe
ProfileImage o-- Image : image
Ownership evidence
PhotosPickerDemo/ProfileModel.swift:17 — stored dependency or nearest verified ownership anchor
@MainActor
class ProfileModel: ObservableObject {
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ProfileModel |
String (firstName) |
owns value state | App/module collaborators |
ProfileModel |
String (lastName) |
owns value state | App/module collaborators |
ProfileModel |
String (aboutMe) |
owns value state | App/module collaborators |
ProfileImage |
Image (image) |
stores or receives | 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. | PhotosPickerDemo/ProfileModel.swift:12 |
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | PhotosPickerDemo/ProfileModel.swift:75 |
@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
PhotosPickerDemo/ProfileModel.swift:12 — representative execution boundary
@MainActor
class ProfileModel: ObservableObject {
// ...
@Published var aboutMe: String = ""
// ...
}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 | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | PhotosPickerDemo/Profile.swift:27 |
| State propagation | ObservableObject |
ObservableObject supplies an observation contract. | PhotosPickerDemo/ProfileModel.swift:13 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | PhotosPickerDemo/ProfileModel.swift:17 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | PhotosPickerDemo/PhotosPickerExampleApp.swift:8 |
| Source import | PhotosUI |
The cited file imports this module; runtime use and architectural role are not inferred. | PhotosPickerDemo/Profile.swift:9 |
| Source import | CoreTransferable |
The cited file imports this module; runtime use and architectural role are not inferred. | PhotosPickerDemo/ProfileModel.swift:10 |
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
PhotosPickerDemo/PhotosPickerExampleApp.swift:11 — representative type boundary
@main
struct PhotosPickerDemoApp: App {
// ...
Profile()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
PhotosPickerDemoApp |
Application entry and top-level composition | App |
ProfileModel |
Feature data or observable state | ObservableObject |
ImageState |
Represents mutable feature state | Concrete collaborators/imported frameworks |
TransferError |
Represents feature failure conditions | Error |
ProfileImage |
Represents a feature value or composable behavior | Transferable |
ProfileImage |
Represents a feature value or composable behavior | View |
CircularProfileImage |
Represents a feature value or composable behavior | View |
EditableCircularProfileImage |
Represents a feature value or composable behavior | View |
Profile |
Represents a feature value or composable behavior | View |
ProfileForm |
Represents a feature value or composable behavior | 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 |
|---|---|---|---|
imageState (PhotosPickerDemo/ProfileModel.swift:58) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
loadTransferable (PhotosPickerDemo/ProfileModel.swift:73) |
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. |
ProfileImage (PhotosPickerDemo/ProfileImage.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
PhotosPickerDemo/ProfileModel.swift:58 — representative boundary
@MainActor
class ProfileModel: ObservableObject {
// ...
@Published private(set) var imageState: ImageState = .empty
// ...
}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 | PhotosPickerDemoApp |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | ProfileModel |
The source’s Model suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Publisher-backed observable state | PhotosPickerDemo/ProfileModel.swift:17 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: PhotosPickerDemoApp; Model: ProfileModel.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
loadTransferable. - Files:
PhotosPickerDemo/ProfileModel.swift,PhotosPickerDemo/ProfileImage.swift,PhotosPickerDemo/Profile.swift.
Architecture takeaways
PhotosPickerExampleAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, PhotosUI, 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 |
|---|---|
PhotosPickerDemo/PhotosPickerExampleApp.swift |
Cited implementation, PhotosPickerDemoApp, SwiftUI |
PhotosPickerDemo/ProfileModel.swift |
Cited implementation, @MainActor, DispatchQueue.main.async, ObservableObject, @Published, CoreTransferable, ProfileModel, ImageState, TransferError, ProfileImage |
PhotosPickerDemo/ProfileImage.swift |
ProfileImage, CircularProfileImage, EditableCircularProfileImage |
PhotosPickerDemo/Profile.swift |
SwiftUI state property wrapper, PhotosUI, Profile, ProfileForm |