Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-07-21View on Apple Developer

Implementing modern collection views

At a glance

Item Summary
Purpose Bring compositional layouts to your app and simplify updating your user interface with diffable data sources.
App architecture A Swift sample bundle with entry-bearing project variants Modern Collection Views Mac, Modern Collection Views, each leading to UIKit APIs.
Main patterns View-controller organization, Delegate or data-source callbacks
Project style 67 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue.main.asyncAfter, DispatchQueue(label:); none alone proves a background thread.
State/event model No structured observation or publisher-scheduling marker indexed.
Key frameworks/packages UIKit, Cocoa, Foundation; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── Modern Collection Views/
│   ├── Compositional Layout/
│   │   ├── Controllers/
│   │   │   ├── ConferenceVideoController.swift
│   │   │   └── ConferenceNewsController.swift
│   │   └── Basics View Controllers/
│   │       └── ItemBadgeSupplementaryViewController.swift
│   ├── Lists/
│   │   └── CustomCellListViewController.swift
│   ├── OutlineViewController.swift
│   ├── Cell Configurations/
│   │   └── CustomConfigurationViewController.swift
│   ├── Diffable/
│   │   ├── WiFiSettingsViewController.swift
│   │   └── TableViewEditingViewController.swift
│   └── AppDelegate.swift
└── Modern Collection Views Mac/
    ├── Compositional Layout/
    │   └── Basics Window Controllers/
    │       └── ItemBadgeSupplementaryWindowController.swift
    ├── Diffable/
    │   └── WiFiSettingsWindowController.swift
    └── AppDelegate.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 29 project/configuration file(s) and 123 source declaration(s).

Overall architecture

Reference code

Modern Collection Views Mac/AppDelegate.swift:10 — architecture anchor

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    // ...
    private var listWindowController = ListWindowController(windowNibName: "ListWindow")
    // ...
}

Interpretation

The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.

Ownership and state

Ownership evidence

Modern Collection Views Mac/Compositional Layout/Basics Window Controllers/ItemBadgeSupplementaryWindowController.swift:13 — stored dependency or nearest verified ownership anchor

class ItemBadgeSupplementaryWindowController: NSWindowController {
    // ...
    static let badgeSupplementaryViewReuseIdentifier = NSUserInterfaceItemIdentifier("contact-badge-reuse-identifier")
    // ...
}
Owner Object or state Relationship Mutation authority
ItemBadgeSupplementaryWindowController NSUserInterfaceItemIdentifier (badgeSupplementaryViewReuseIdentifier) creates and retains Initialized by the owner; the binding is immutable
Model String (title) owns value state Initialized by the owner; the binding is immutable
Model Int (badgeCount) owns value state Initialized by the owner; the binding is immutable
Model UUID (identifier) 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.

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.asyncAfter The source addresses the main dispatch queue. Modern Collection Views Mac/Diffable/InsertionSortWindowController.swift:82
Queue scheduling DispatchQueue(label:) The source constructs a dispatch queue; its label alone does not prove a thread. Modern Collection Views Mac/Diffable/InsertionSortWindowController.swift:121

@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

Modern Collection Views Mac/Diffable/InsertionSortWindowController.swift:82 — representative execution boundary

        DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(delay)) {
            if shouldReset {
                let randomizedSnapshot = self.snapshot(for: bounds)
                self.dataSource.apply(randomizedSnapshot, animatingDifferences: false)
            }
            self.performSortStep()
        }

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 UIKit The cited file imports this module; runtime use and architectural role are not inferred. Modern Collection Views/AppDelegate.swift:8
Source import Cocoa The cited file imports this module; runtime use and architectural role are not inferred. Modern Collection Views Mac/AppDelegate.swift:8
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. Modern Collection Views Mac/Diffable/MountainsController.swift:8

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

Modern Collection Views Mac/AppDelegate.swift:11 — representative type boundary

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    // ...
    private var listWindowController = ListWindowController(windowNibName: "ListWindow")
    // ...
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
ConferenceVideoController View lifecycle, callbacks, and feature coordination Concrete collaborators/imported frameworks
CustomCellListViewController View lifecycle, callbacks, and feature coordination UIViewController
OutlineViewController View lifecycle, callbacks, and feature coordination UIViewController
ItemBadgeSupplementaryWindowController View lifecycle, callbacks, and feature coordination NSWindowController
Model Feature data or observable state Hashable
BadgeView User-interface presentation and input forwarding NSBox, NSCollectionViewElement
WiFiSettingsWindowController View lifecycle, callbacks, and feature coordination NSWindowController
CustomConfigurationViewController View lifecycle, callbacks, and feature coordination UIViewController

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
listWindowController (Modern Collection Views Mac/AppDelegate.swift:13) 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.
gridWindowController (Modern Collection Views Mac/AppDelegate.swift:14) 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.
insetItemsGridWindowController (Modern Collection Views Mac/AppDelegate.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.
twoColumnWindowController (Modern Collection Views Mac/AppDelegate.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.

Reference code

Modern Collection Views Mac/AppDelegate.swift:13 — representative boundary

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    // ...
    private var listWindowController = ListWindowController(windowNibName: "ListWindow")
    // ...
}

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 AdaptiveSectionsViewController, AdaptiveSectionsWindowController, ConferenceNewsController, ConferenceNewsFeedViewController The source’s Controller suffix makes this role explicit.
Supplies data through a callback contract DataSource 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 Model The source’s Model suffix makes this role explicit.
User-interface presentation and input forwarding BadgeSupplementaryView, BadgeView, CustomContentView, SectionBackgroundDecorationView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Modern Collection Views/Compositional Layout/Basics View Controllers/AdaptiveSectionsViewController.swift:10 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Delegate or data-source callbacks Modern Collection Views Mac/AppDelegate.swift:11 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: Controller: AdaptiveSectionsViewController, AdaptiveSectionsWindowController, ConferenceNewsController, ConferenceNewsFeedViewController, ConferenceVideoController; DataSource: DataSource; Delegate: AppDelegate; Model: Model; View: BadgeSupplementaryView, BadgeView, CustomContentView, SectionBackgroundDecorationView, TitleSupplementaryView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: hash, generateCollections, viewDidLoad, createLayout, configureHierarchy, configureDataSource, collectionView, updateWithItem.
  • Files: Modern Collection Views/Compositional Layout/Controllers/ConferenceVideoController.swift, Modern Collection Views/Lists/CustomCellListViewController.swift, Modern Collection Views/OutlineViewController.swift, Modern Collection Views Mac/Compositional Layout/Basics Window Controllers/ItemBadgeSupplementaryWindowController.swift, Modern Collection Views Mac/Diffable/WiFiSettingsWindowController.swift, Modern Collection Views/Cell Configurations/CustomConfigurationViewController.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches UIKit, Cocoa 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
Modern Collection Views Mac/AppDelegate.swift Cited implementation, AppDelegate, Cocoa
Modern Collection Views Mac/Compositional Layout/Basics Window Controllers/ItemBadgeSupplementaryWindowController.swift Cited implementation, ItemBadgeSupplementaryWindowController, Section, Model, BadgeView
Modern Collection Views/Compositional Layout/Basics View Controllers/AdaptiveSectionsViewController.swift AdaptiveSectionsViewController, SectionLayoutKind
Modern Collection Views Mac/Diffable/InsertionSortWindowController.swift DispatchQueue.main.asyncAfter, DispatchQueue(label:), InsertionSortWindowController
Modern Collection Views/AppDelegate.swift UIKit, AppDelegate
Modern Collection Views Mac/Diffable/MountainsController.swift Foundation, MountainsController, Mountain
Modern Collection Views/Compositional Layout/Controllers/ConferenceVideoController.swift ConferenceVideoController, Video, VideoCollection
Modern Collection Views/Lists/CustomCellListViewController.swift Section, Category, Item, CustomCellListViewController, ItemListCell, CustomListCell
Modern Collection Views/OutlineViewController.swift OutlineViewController, Section, OutlineItem
Modern Collection Views Mac/Diffable/WiFiSettingsWindowController.swift WiFiSettingsWindowController, Section, ItemType, Item
Modern Collection Views/Cell Configurations/CustomConfigurationViewController.swift Section, Item, CustomConfigurationViewController, CustomConfigurationCell
Modern Collection Views/Diffable/WiFiSettingsViewController.swift WiFiSettingsViewController, Section, ItemType, Item
Modern Collection Views/Compositional Layout/Controllers/ConferenceNewsController.swift ConferenceNewsController, NewsFeedItem
Modern Collection Views/Compositional Layout/Basics View Controllers/ItemBadgeSupplementaryViewController.swift ItemBadgeSupplementaryViewController, Section, Model
Modern Collection Views/Diffable/TableViewEditingViewController.swift TableViewEditingViewController, Section, DataSource
Modern Collection Views/Lists/ReorderableListViewController.swift ReorderableListViewController, Item, ReorderingMethod