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

Supporting desktop-class features in your iPad app

At a glance

Item Summary
Purpose Enhance your iPad app by adding desktop-class features and document support.
App architecture A Swift sample with the source-visible chain AppDelegateDocumentBrowserViewControllerMarkdownDocumentUIKit APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks
Project style 17 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 UIKit, Foundation, UniformTypeIdentifiers, WebKit; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── DesktopClassMarkdownEditor/
    └── DesktopClassMarkdownEditor/
        ├── AppDelegate.swift
        ├── Views/
        │   ├── OutlineViewController.swift
        │   ├── EditorViewController.swift
        │   ├── SplitView.swift
        │   ├── SplitViewController.swift
        │   ├── DocumentBrowserViewController.swift
        │   ├── EditorView.swift
        │   └── PreviewView.swift
        ├── Document Management/
        │   └── MarkDownDocument.swift
        ├── SceneDelegate.swift
        └── Markdown/
            ├── MarkdownTag.swift
            └── Outline.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 6 project/configuration file(s) and 25 source declaration(s).

Overall architecture

Reference code

DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/AppDelegate.swift:10 — architecture anchor

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    // ...
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        return true
    }
    // ...
}

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 UIKit.

Ownership and state

Ownership evidence

DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/OutlineViewController.swift:19 — stored dependency or nearest verified ownership anchor

class OutlineViewController: UIViewController, UICollectionViewDelegate {
    // ...
    weak var delegate: OutlineViewControllerDelegate?
    // ...
}
Owner Object or state Relationship Mutation authority
OutlineViewController OutlineViewControllerDelegate (delegate) holds a non-owning reference The referenced object’s lifecycle is owned elsewhere
OutlineViewController Array (outlineElements) owns value state App/module collaborators
OutlineViewController UICollectionViewDiffableDataSource (dataSource) stores or receives Owning lexical scope
EditorViewController EditorView (editorTextView) creates and retains 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.async The source addresses the main dispatch queue. DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/EditorViewController.swift:336

@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

DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/EditorViewController.swift:336 — representative execution boundary

                DispatchQueue.main.async {
                    self.previewView.webView.loadHTMLString(parsedDocument.html, baseURL: Bundle.main.resourceURL)
                    self.delegate?.editor(self, didParse: parsedDocument)
                    self.syncScrollPositionIfNecessary()
                }

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. DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/AppDelegate.swift:8
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Markdown/MarkdownNode.swift:8
Source import UniformTypeIdentifiers The cited file imports this module; runtime use and architectural role are not inferred. DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/DocumentBrowserViewController.swift:10
Source import WebKit The cited file imports this module; runtime use and architectural role are not inferred. DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/PreviewView.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

DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/OutlineViewController.swift:10 — representative type boundary

protocol OutlineViewControllerDelegate: AnyObject {
    func outline(_ outlineView: OutlineViewController, didChoose element: OutlineElement)
    func outline(_ outlineView: OutlineViewController, didSwapTagsFor elements: [OutlineElement], withTag: MarkdownTag)
    func outline(_ outlineView: OutlineViewController, didDuplicate elements: [OutlineElement])
    func outline(_ outlineView: OutlineViewController, didDelete elements: [OutlineElement])
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
OutlineViewControllerDelegate Defines a capability or collaboration contract AnyObject
EditorViewControllerDelegate Defines a capability or collaboration contract AnyObject
OutlineViewController View lifecycle, callbacks, and feature coordination UIViewController, UICollectionViewDelegate
EditorViewController View lifecycle, callbacks, and feature coordination UIDocumentViewController
SplitView User-interface presentation and input forwarding UIView, UIPointerInteractionDelegate
SplitViewController View lifecycle, callbacks, and feature coordination UISplitViewController, EditorViewControllerDelegate, OutlineViewControllerDelegate
MarkdownDocument Owns document data or lifecycle behavior UIDocument
SceneDelegate Receives callback-driven events UIResponder, UIWindowSceneDelegate
DocumentBrowserViewController View lifecycle, callbacks, and feature coordination UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate, UIViewControllerTransitioningDelegate

The source explicitly defines local protocol relationships: SplitViewControllerEditorViewControllerDelegate, SplitViewControllerOutlineViewControllerDelegate.

Access control

Symbol Access Verified effect Likely rationale
updateTextContent (DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Document Management/MarkDownDocument.swift:113) 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.
htmlTransformer (DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Markdown/MarkdownTag.swift:46) 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.
updateFontScale (DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/EditorView.swift:58) 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.
configureCenterItemGroups (DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/EditorViewController.swift:172) 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.

Reference code

DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Document Management/MarkDownDocument.swift:113 — representative boundary

    private func updateTextContent() {
        text = parsedDocument!.textContent()
        // ...
    }

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 DocumentBrowserViewController, EditorViewController, OutlineViewController, SplitViewController The source’s Controller suffix makes this role explicit.
Receives callback-driven events AppDelegate, EditorViewControllerDelegate, OutlineViewControllerDelegate, SceneDelegate The source’s Delegate suffix makes this role explicit.
Owns document data or lifecycle behavior MarkdownDocument, ParsedDocument The source’s Document suffix makes this role explicit.
User-interface presentation and input forwarding EditorView, PreviewView, SplitView The source’s View suffix makes this role explicit.

Design patterns

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

Naming conventions

  • Types: Controller: DocumentBrowserViewController, EditorViewController, OutlineViewController, SplitViewController; Delegate: AppDelegate, EditorViewControllerDelegate, OutlineViewControllerDelegate, SceneDelegate; Document: MarkdownDocument, ParsedDocument; View: EditorView, PreviewView, SplitView.
  • Protocols: OutlineViewControllerDelegate, EditorViewControllerDelegate.
  • Methods: application, outline, loadView, viewDidLoad, configureDataSource, updateSnapshot, collectionView, tagSpecificActions.
  • Files: DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/AppDelegate.swift, DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/OutlineViewController.swift, DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/EditorViewController.swift, DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/SplitView.swift, DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/SplitViewController.swift, DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/SceneDelegate.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches UIKit, UniformTypeIdentifiers, WebKit 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
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/AppDelegate.swift Cited implementation, UIKit, AppDelegate
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/OutlineViewController.swift Cited implementation, OutlineViewControllerDelegate, OutlineViewController, Section
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Document Management/MarkDownDocument.swift Cited implementation, MarkdownDocument
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Markdown/MarkdownTag.swift Cited implementation, MarkdownTag, Options, Language
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/EditorView.swift Cited implementation, EditorView
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/EditorViewController.swift Cited implementation, DispatchQueue.main.async, EditorViewControllerDelegate, EditorViewController
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/DocumentBrowserViewController.swift DocumentBrowserViewController, UniformTypeIdentifiers
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/SplitViewController.swift Cited implementation, SplitViewController, SplitViewError
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Markdown/MarkdownNode.swift Foundation, MarkdownNode
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/PreviewView.swift WebKit, PreviewView
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/SplitView.swift SplitViewResizeGesture, SplitView
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/SceneDelegate.swift SceneDelegate
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Markdown/Outline.swift OutlineElement, OutlineRepresentation
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Markdown/Parser.swift ParsedDocument, Parser
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/ResizeKnob.swift ResizeKnob
DesktopClassMarkdownEditor/DesktopClassMarkdownEditor/Views/TextSizeSlider.swift TextSizeSlider