Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-11-01View on Apple Developer

Integrating your photo app with Apple Intelligence

At a glance

Item Summary
Purpose Adopt photos-domain App Intents schemas so Siri can create, open, update, delete, and search assets and albums backed by the Photos library.
App architecture PhotosDomainExample creates one MediaLibrary and one NavigationManager, injects both into SwiftUI through environment and into App Intents through AppDependencyManager.
Main patterns Observable state owners shared by views and intents; two actors (ImageManager, LocationManager) isolate PhotoKit image caching and reverse-geocoding.
Project style AppIntents/ (entities, intents, shortcuts by Album/Asset), Managers/, Model/, Views/ (Album/Asset), one multiplatform app target.
Execution model The target compiles with default MainActor isolation; nonisolated static helpers wrap PhotoKit changes; actors serialize caching and geocoding.
State/event model @Observable MediaLibrary (assets, albums) and NavigationManager (paths, tab, search text) drive SwiftUI; intents mutate them directly.
Key frameworks/packages AppIntents, Photos, CoreSpotlight, GeoToolbox, MapKit, SwiftUI; no Swift package manifest.

Project structure

PhotosDomainExample/
├── PhotosDomainExample.swift     app entry, dependency registration
├── ContentView.swift             TabView bound to NavigationManager
├── AppIntents/
│   ├── Album/                    AlbumEntity, AlbumIntents, AlbumType
│   ├── Asset/                    AssetEntity, AssetIntents, AssetFilter, AssetType
│   └── ShortcutsProvider.swift   App Shortcuts phrases
├── Managers/
│   ├── MediaLibrary.swift        Photos fetch/change + Spotlight indexing
│   ├── NavigationManager.swift   tab, paths, search text
│   ├── ImageManager.swift        actor over PHCachingImageManager
│   └── LocationManager.swift     actor serializing reverse geocoding
├── Model/                        Asset, Album (@Observable wrappers of PhotoKit)
└── Views/                        Album/ and Asset/ grids, stacks, detail views

Structure observations

  • Each AppIntents/ subfolder pairs an entity with its intents and value enums, mirroring the schema domain (PhotosDomainExample/AppIntents/Album/AlbumIntents.swift:11).
  • Model classes wrap PhotoKit objects and expose an entity conversion for App Intents (PhotosDomainExample/Model/Asset.swift:122).

Overall architecture

Reference code

PhotosDomainExample/PhotosDomainExample.swift:23 — PhotosDomainExample

@main
struct PhotosDomainExample: App {

    // MARK: Life cycle

    let library: MediaLibrary
    let navigationManager: NavigationManager

    init() {
        let navigationManager = NavigationManager()
        let library = MediaLibrary()
        library.load()
        AppDependencyManager.shared.add(dependency: library)
        AppDependencyManager.shared.add(dependency: navigationManager)
        self.library = library
        self.navigationManager = navigationManager
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .environment(library)
        .environment(navigationManager)
    }
}

Interpretation

The app struct is the composition root: it constructs both observable owners once, registers them with App Intents, and places them in the SwiftUI environment. Intents and views therefore read and write the same instances, so a Siri-driven change appears in the UI without a separate synchronization step.

Platform boundary

Apple lists Mac Catalyst, but the target sets SUPPORTS_MACCATALYST = NO and builds for native macOS through SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx" (PhotosDomainExample.xcodeproj/project.pbxproj:538). Code branches with #if os(macOS) for NSImage (PhotosDomainExample/Managers/ImageManager.swift:66).

Ownership and state

Ownership evidence

PhotosDomainExample/Managers/MediaLibrary.swift:21 — MediaLibrary

@Observable
final class MediaLibrary {
    // ...
    private(set) var assets: [Asset] = []
    private(set) var albums: [Album] = []

    // MARK: Internal Methods

    func load() {
        Task {
            async let assets: Void = self.fetchAssets()
            async let albums: Void = self.fetchAlbums()
            _ = await (assets, albums)
        }
    }
    // ...
}
Owner Object or state Relationship Mutation authority
PhotosDomainExample MediaLibrary, NavigationManager Creates and retains in let properties —
MediaLibrary assets, albums arrays Owns; private(set) Only MediaLibrary methods (createAsset, deleteAssets, createAlbum, fetches)
Asset PHAsset, place, isFavorite, isHidden Wraps PhotoKit object; caches derived state Asset.setIsFavorite, setIsHidden, fetchPlacemark (PhotosDomainExample/Model/Asset.swift:86)
NavigationManager libraryPath, albumPath, selection, searchText Owns observable state openAsset, openAlbum, openSearch, and view bindings
ImageManager.shared PHCachingImageManager, cachedAssetIdentifiers Actor-owned, private Actor methods only
AssetEntity asset: Asset Holds a reference to the model for Transferable export Read-only (PhotosDomainExample/AppIntents/Asset/AssetEntity.swift:22)

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-actor isolation Build setting SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor Unannotated types such as MediaLibrary, NavigationManager, and Asset default to the main actor PhotosDomainExample.xcodeproj/project.pbxproj:427
Main-actor isolation Explicit @MainActor Entity queries and most intent perform() methods PhotosDomainExample/AppIntents/Album/AlbumEntity.swift:40
Off-actor helpers nonisolated private static ... async PhotoKit fetch and performChanges helpers that touch no instance state; the source comment states they run off the main actor PhotosDomainExample/Managers/MediaLibrary.swift:162
Task creation Task {} with async let load() fetches assets and albums concurrently; the task is not stored or cancelled PhotosDomainExample/Managers/MediaLibrary.swift:27
Shared-state safety actor ImageManager cachedAssetIdentifiers and the caching manager are mutated only inside the actor PhotosDomainExample/Managers/ImageManager.swift:11
Serialization actor LocationManager + chained Task Each lookup awaits the previous task’s result, so geocoding requests run one at a time PhotosDomainExample/Managers/LocationManager.swift:27
Callback bridge withCheckedThrowingContinuation Converts requestImage’s completion handler into an async result PhotosDomainExample/Managers/ImageManager.swift:54
View-scoped tasks .task(id:) SwiftUI starts and cancels image loading per asset identity PhotosDomainExample/Views/Asset/AssetItem.swift:32

Reference code

PhotosDomainExample/Managers/LocationManager.swift:29 — LocationManager.lookUp

actor LocationManager {
    // ...
    private var currentTask: Task<PlaceDescriptor, Error>?

    // MARK: Methods

    func lookUp(_ location: CLLocation) async throws -> PlaceDescriptor {
        // Chain onto any in-flight lookup so requests are serialized.
        let previousTask = currentTask
        let task = Task {
            // Await any previous processing.
            _ = await previousTask?.result
            // ...
        }
        currentTask = task

        // Await new task completion.
        return try await task.value
    }
}

The actor stores only the latest task; earlier tasks are retained by the closures that await them. Nothing cancels the chain. Asset.fetchPlacemark() re-checks place == nil after the await because another caller may have resolved it during the suspension (PhotosDomainExample/Model/Asset.swift:79).

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 @Environment(MediaLibrary.self) Views read the shared library PhotosDomainExample/ContentView.swift:14
State propagation @Bindable on NavigationManager Binds the tab selection and stack paths so intents can drive navigation PhotosDomainExample/Views/Asset/AssetStack.swift:21
Dependency registration AppDependencyManager / @Dependency Supplies the same owners to intents and queries PhotosDomainExample/AppIntents/Asset/AssetIntents.swift:46
Spotlight CSSearchableIndex.default().indexAppEntities Library writes and fetches re-index entities PhotosDomainExample/Managers/MediaLibrary.swift:44
Entity export Transferable DataRepresentation(.png) AssetEntity exports image data through ImageManager PhotosDomainExample/AppIntents/Asset/AssetEntity.swift:67
Framework import GeoToolbox, MapKit Reverse-geocoding into PlaceDescriptor PhotosDomainExample/Managers/LocationManager.swift:9

No Combine publisher scheduling appears in the reviewed files.

Class and protocol design

Reference code

PhotosDomainExample/AppIntents/Asset/AssetIntents.swift:42 — OpenAssetIntent

@AppIntent(schema: .system.open)
struct OpenAssetIntent: OpenIntent {
    var target: AssetEntity

    @Dependency
    var library: MediaLibrary

    @Dependency
    var navigation: NavigationManager
    // ...
}
Type Responsibility Depends on
AssetEntity, AlbumEntity Schema entities (photos.asset, photos.album) with nested queries MediaLibrary
Asset intents (CreateAssetsIntent, OpenAssetIntent, UpdateAssetIntent, DeleteAssetsIntent, SearchAssetsIntent) Translate schema parameters into library or navigation calls MediaLibrary, NavigationManager
Album intents (CreateAlbumIntent … RemoveAssetsFromAlbumIntent) Album CRUD and membership through the library MediaLibrary
ExampleAppShortcutsProvider Phrases for create, open, and search Intent types
MediaLibrary Authorization, PhotoKit fetch/change, Spotlight indexing PHPhotoLibrary, CSSearchableIndex
ImageManager, LocationManager Actor-isolated image caching and geocoding PHCachingImageManager, MKReverseGeocodingRequest

No local protocol is declared; conformances are to App Intents and SwiftUI protocols.

Access control

Symbol Access Verified effect Likely rationale
MediaLibrary.assets, albums private(set) Any file can read; only MediaLibrary can assign Inference: route all mutations through methods that also update Photos and Spotlight
MediaLibrary PhotoKit helpers nonisolated private static File-private to the type and free of main-actor isolation Inference: keep blocking PhotoKit work off the UI actor without exposing it
ImageManager.imageManager, cachedAssetIdentifiers private Only actor methods touch the caching manager Inference: actor isolation plus privacy keeps cache bookkeeping consistent
LocationManager.currentTask private var Only lookUp reads and replaces the chain head Inference: protect the serialization invariant
ContentView.library, navigation private Environment values are view-local Inference: views do not expose injected owners

Reference code

PhotosDomainExample/Managers/MediaLibrary.swift:162 — fetchAllPhotoAssets()

    nonisolated private static func fetchAllPhotoAssets() async -> [PHAsset] {
        let fetchResult = PHAsset.fetchAssets(with: nil)
        var phAssets = [PHAsset]()
        fetchResult.enumerateObjects { (object, _, _) in
            phAssets.append(object)
        }
        return phAssets
    }

Logic ownership and placement

Logic Owning type or file Placement rationale
Photo-library authorization and fetch MediaLibrary One owner gates every read on authorization (PhotosDomainExample/Managers/MediaLibrary.swift:134)
Spotlight index maintenance MediaLibrary, Asset.fetchPlacemark Index updates sit beside the mutation that changed the entity
Favorite/hidden edits Asset The model owns its PhotoKit change request and local mirror
Siri navigation (open, searchInApp) NavigationManager Intents set paths or search text; stacks bind to them (PhotosDomainExample/AppIntents/Asset/AssetIntents.swift:115)
Image loading and caching ImageManager actor Views call it from .task and onAppear

Design patterns

Pattern Source evidence Purpose or tradeoff
Observable state owner PhotosDomainExample/Managers/MediaLibrary.swift:12, PhotosDomainExample/Managers/NavigationManager.swift:11 Views and intents observe and mutate one instance each
SwiftUI environment injection PhotosDomainExample/PhotosDomainExample.swift:33 Views receive owners without singletons
App Intents dependency injection PhotosDomainExample/PhotosDomainExample.swift:23 Intents receive the same owners via @Dependency
Actor isolation PhotosDomainExample/Managers/ImageManager.swift:11, PhotosDomainExample/Managers/LocationManager.swift:12 Protects cache bookkeeping and serializes geocoding
Callback-to-async continuation bridge PhotosDomainExample/Managers/ImageManager.swift:54 Lets SwiftUI .task await a PhotoKit callback

Main application flow

Scope: Siri opens a specific photo through the system.open schema.

Reference code

PhotosDomainExample/AppIntents/Asset/AssetIntents.swift:59 — OpenAssetIntent.perform()

    @MainActor
    func perform() async throws -> some IntentResult {
        let assets = library.assets(for: [target.id])
        guard let asset = assets.first else {
            throw IntentError.noEntity
        }

        navigation.openAsset(asset)
        return .result()
    }

PhotosDomainExample/Managers/NavigationManager.swift:30 — openAsset

    func openAsset(_ asset: Asset) {
        selection = .library
        libraryPath = NavigationPath([asset])
    }

PhotosDomainExample/Views/Asset/AssetStack.swift:21 — AssetStack.body

    var body: some View {
        @Bindable var navigation = navigation
        NavigationStack(path: $navigation.libraryPath) {
            AssetGrid(assets: library.assets)
        }
    }

Naming conventions

  • Types: <Domain>Entity with nested <Domain>Query; <Verb><Noun>Intent; <Role>Manager for the navigation owner and the two actors; MediaLibrary for the Photos-backed store.
  • Protocols: none declared locally.
  • Methods: open… for navigation commands, create…/delete…/import… for library mutations, set… for asset edits, fetchAll… for nonisolated PhotoKit helpers.
  • Files and extensions: intents for one domain share a file (AssetIntents.swift, AlbumIntents.swift); views are grouped by domain folder.

Architecture takeaways

  • Build owners once in the App initializer and register them with both environment and AppDependencyManager so Siri and UI share state.
  • Model Siri navigation as observable path and tab state that NavigationStack and TabView bind to.
  • Use private(set) collections plus methods that also update Photos and Spotlight, keeping index and UI consistent.
  • Use a small actor with a chained task to serialize a rate-sensitive service like reverse-geocoding, and re-check state after each suspension.
  • Wrap callback-based PhotoKit image requests in a continuation inside an actor so views can await them from .task.

Source map

Source file Relevant symbols
PhotosDomainExample/PhotosDomainExample.swift PhotosDomainExample, dependency registration
PhotosDomainExample/ContentView.swift ContentView
PhotosDomainExample/Managers/MediaLibrary.swift MediaLibrary, load, fetchAllPhotoAssets
PhotosDomainExample/Managers/NavigationManager.swift NavigationManager, openAsset
PhotosDomainExample/Managers/ImageManager.swift ImageManager, requestImage
PhotosDomainExample/Managers/LocationManager.swift LocationManager, lookUp
PhotosDomainExample/Model/Asset.swift Asset, fetchPlacemark, entity
PhotosDomainExample/AppIntents/Asset/AssetIntents.swift OpenAssetIntent, SearchAssetsIntent
PhotosDomainExample/AppIntents/Asset/AssetEntity.swift AssetEntity, AssetQuery
PhotosDomainExample/AppIntents/Album/AlbumEntity.swift AlbumEntity, AlbumQuery
PhotosDomainExample/AppIntents/Album/AlbumIntents.swift CreateAlbumIntent
PhotosDomainExample/Views/Asset/AssetStack.swift AssetStack
PhotosDomainExample/Views/Asset/AssetItem.swift .task(id:)
PhotosDomainExample.xcodeproj/project.pbxproj build settings