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, Actor-isolated state |
| Project style | 4 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
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.
Class and protocol design
PhotosPickerDemo/PhotosPickerExampleApp.swift:11 — representative type boundary
struct PhotosPickerDemoApp: App {
var body: some Scene {
WindowGroup {
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. |
| Actor-isolated state | PhotosPickerDemo/ProfileModel.swift:12 |
Actor annotations make the concurrency ownership boundary explicit. |
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 |
PhotosPickerDemoApp |
PhotosPickerDemo/ProfileModel.swift |
ProfileModel, ImageState, TransferError, ProfileImage |
PhotosPickerDemo/ProfileImage.swift |
ProfileImage, CircularProfileImage, EditableCircularProfileImage |
PhotosPickerDemo/Profile.swift |
Profile, ProfileForm |