Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Creating a Slideshow Project Extension for Photos

At a glance

Item Summary
Purpose Augment the macOS Photos app with extensions that support project creation.
App architecture A Swift sample with the source-visible chain AppDelegateGridViewControllerAssetModelPhotosUI / Photos APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks
Project style 14 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue.main.async; none alone proves a background thread.
State/event model No structured observation or publisher-scheduling marker indexed.
Key frameworks/packages Cocoa, PhotosUI, CoreGraphics, Foundation, Photos; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── Photos Project Slideshow/
│   └── AppDelegate.swift
└── Slideshow Sample/
    ├── Model/
    │   ├── ProjectModel.swift
    │   ├── AssetModel.swift
    │   └── ProjectModel+Persistence.swift
    ├── Grid/
    │   ├── CollectionViewDataSource.swift
    │   ├── GridViewController.swift
    │   └── AssetCollectionViewItem.swift
    ├── PhotoProjectViewController.swift
    └── Slides/
        ├── SimpleImageView.swift
        ├── SlideViewController.swift
        ├── SlideshowViewController.swift
        └── Animator.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 13 project/configuration file(s) and 13 source declaration(s).

Overall architecture

Reference code

Photos Project Slideshow/AppDelegate.swift:10 — architecture anchor

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application.
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application.
    }

}

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

Ownership evidence

Photos Project Slideshow/AppDelegate.swift:13 — stored dependency or nearest verified ownership anchor

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    // ...
    @IBOutlet weak var window: NSWindow!
    // ...
}
Owner Object or state Relationship Mutation authority
AppDelegate NSWindow (window) holds a non-owning reference The referenced object’s lifecycle is owned elsewhere
ProjectModel PHProjectInfo (projectInfo) stores or receives Initialized by the owner; the binding is immutable
CollectionViewDataSource NSUserInterfaceItemIdentifier (reuseIdentifier) creates and retains Initialized by the owner; the binding is immutable
GridViewController NSCollectionView (collectionView) stores or receives App/module collaborators

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
Queue scheduling DispatchQueue.main.async The source addresses the main dispatch queue. Slideshow Sample/PhotoProjectViewController.swift:40

@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

Slideshow Sample/PhotoProjectViewController.swift:40 — representative execution boundary

        super.viewDidAppear()
        DispatchQueue.main.async {
            self.view.window?.makeFirstResponder(self)
        }

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
Source import Cocoa The cited file imports this module; runtime use and architectural role are not inferred. Photos Project Slideshow/AppDelegate.swift:8
Source import PhotosUI The cited file imports this module; runtime use and architectural role are not inferred. Slideshow Sample/Grid/GridViewController.swift:9
Source import CoreGraphics The cited file imports this module; runtime use and architectural role are not inferred. Slideshow Sample/Slides/Geometry.swift:8
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. Slideshow Sample/Model/AssetModel.swift:8
Source import Photos The cited file imports this module; runtime use and architectural role are not inferred. Slideshow Sample/Grid/AssetCollectionViewItem.swift:9

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

Slideshow Sample/Slides/Animator.swift:11 — representative type boundary

protocol AnimatableSlide {
    var contentAspectRatio: CGFloat? { get }
    var preferredZoomRect: CGRect? { get }
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate
ProjectModel Feature data or observable state NSObject, NSSecureCoding
CollectionViewDataSource Supplies data through a callback contract NSObject, NSCollectionViewDataSource
GridViewController View lifecycle, callbacks, and feature coordination NSViewController
AssetModel Feature data or observable state Concrete collaborators/imported frameworks
PhotoProjectViewController View lifecycle, callbacks, and feature coordination NSViewController, PHProjectExtensionController, PHPhotoLibraryChangeObserver
SimpleImageView User-interface presentation and input forwarding NSView
SlideViewController View lifecycle, callbacks, and feature coordination NSViewController
SlideshowViewController View lifecycle, callbacks, and feature coordination NSViewController
AnimatableSlide Defines a capability or collaboration contract Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: RoiZoomAnimatorAnimator, SlideViewControllerAnimatableSlide.

Access control

Symbol Access Verified effect Likely rationale
contentMode (Slideshow Sample/Slides/SlideViewController.swift:15) 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.
imageManager (Slideshow Sample/Slides/SlideViewController.swift:16) 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.
requestID (Slideshow Sample/Slides/SlideViewController.swift:17) 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.
modelIterator (Slideshow Sample/Slides/SlideshowViewController.swift:20) 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

Slideshow Sample/Slides/SlideViewController.swift:15 — representative boundary

class SlideViewController: NSViewController {
    // ...
    private var contentMode: PHImageContentMode = .aspectFit
    // ...
}

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
View lifecycle, callbacks, and feature coordination GridViewController, PhotoProjectViewController, SlideViewController, SlideshowViewController The source’s Controller suffix makes this role explicit.
Supplies data through a callback contract CollectionViewDataSource The source’s DataSource suffix makes this role explicit.
Receives callback-driven events AppDelegate The source’s Delegate suffix makes this role explicit.
Feature data or observable state AssetModel, ProjectModel The source’s Model suffix makes this role explicit.
User-interface presentation and input forwarding SimpleImageView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Slideshow Sample/Grid/GridViewController.swift:11 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction Slideshow Sample/Slides/Animator.swift:26 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks Photos Project Slideshow/AppDelegate.swift:11 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: Controller: GridViewController, PhotoProjectViewController, SlideViewController, SlideshowViewController; DataSource: CollectionViewDataSource; Delegate: AppDelegate; Model: AssetModel, ProjectModel; View: SimpleImageView.
  • Protocols: AnimatableSlide, Animator.
  • Methods: applicationDidFinishLaunching, applicationWillTerminate, encode, collectionView, viewDidLoad, loadCollectionView, models, viewDidAppear.
  • Files: Photos Project Slideshow/AppDelegate.swift, Slideshow Sample/Model/ProjectModel.swift, Slideshow Sample/Grid/CollectionViewDataSource.swift, Slideshow Sample/Grid/GridViewController.swift, Slideshow Sample/Model/AssetModel.swift, Slideshow Sample/PhotoProjectViewController.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Cocoa, PhotosUI, CoreGraphics, Photos 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.
  • Local protocol relationships provide an explicit substitution boundary.

Source map

Source file Relevant symbols
Photos Project Slideshow/AppDelegate.swift Cited implementation, Cocoa, AppDelegate
Slideshow Sample/Slides/Animator.swift AnimatableSlide, Cited implementation, Animator, RoiZoomAnimator
Slideshow Sample/Slides/SlideViewController.swift Cited implementation, SlideViewController
Slideshow Sample/Slides/SlideshowViewController.swift Cited implementation, SlideshowViewController
Slideshow Sample/Grid/GridViewController.swift GridViewController, PhotosUI
Slideshow Sample/PhotoProjectViewController.swift DispatchQueue.main.async, PhotoProjectViewController
Slideshow Sample/Slides/Geometry.swift CoreGraphics, Feature implementation
Slideshow Sample/Model/AssetModel.swift Foundation, AssetModel
Slideshow Sample/Grid/AssetCollectionViewItem.swift Photos, AssetCollectionViewItem
Slideshow Sample/Model/ProjectModel.swift ProjectModel, CodingKeys
Slideshow Sample/Grid/CollectionViewDataSource.swift CollectionViewDataSource
Slideshow Sample/Slides/SimpleImageView.swift SimpleImageView
Slideshow Sample/Model/ProjectModel+Persistence.swift func
Slideshow Sample/Slides/SlideViewController+AnimatorSlide.swift Feature implementation