Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2023 SwiftDeveloper Tools

WWDC23 · 34 min · Swift / Developer Tools

Create rich documentation with Swift-DocC

Learn how you can take advantage of the latest features in Swift-DocC to create rich and detailed documentation for your app or framework. We’ll show you how to use the Xcode 15 Documentation Preview editor to efficiently iterate on your existing project’s documentation, and explore expanded authoring capabilities like grid-based layouts, video support, and custom themes. To get the most out of this session, you should have a working knowledge of the basics of Swift-DocC documentation.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

  • 0:00 — Introduction and overview of Swift-DocC
  • 3:33 — Building and browsing documentation in Xcode
  • 6:21 — Documenting Swift extensions
  • 8:05 — Activating the Documentation Preview editor
  • 9:44 — Adding an image to your documentation
  • 12:06 — Organizing documentation pages into Topic Groups
  • 13:53 — Using Swift-DocC directives to create rich documentation pages
  • 25:12 — Theming the online version of your documentation
  • 28:29 — Publishing and browsing documentation on the web
  • 31:02 — Quick navigation

Code shown on screen · 11 snippets

Documenting a Swift extension swift · at 8:52 ↗
import SwiftUI

/// An extension that facilitates the display of sloths in user interfaces.
public extension Image {
    /// Create an image from the given sloth.
    ///
    /// Use this initializer to display an image representation of a
    /// given sloth.
    ///
    /// ```swift
    /// let iceSloth = Sloth(name: "Super Sloth", color: .blue, power: .ice)
    ///
    /// var body: some View {
    ///     Image(iceSloth)
    ///         .resizable()
    ///         .aspectRatio(contentMode: .fit)
    ///     Text(iceSloth.name)
    /// }
    /// ```
    ///
    /// ![A screenshot of an ice sloth, with the text Super Sloth underneath.](iceSloth)
    ///
    /// This initializer is useful for displaying static sloth images.
    /// To create an interactive view containing a sloth, use ``SlothView``.
    init(_ sloth: Sloth) {
        self.init("\(sloth.power)-sloth")
    }
}
Creating a grid-based layout markdown · at 16:31 ↗
@Row {
    @Column(size: 2) {
        First, you customize your sloth by picking its 
        ``Sloth/power-swift.property``. The power of your sloth influences
        its abilities and how well they cope in their environment. The app
        displays a picker view that showcases the available powers and
        previews your sloth for the selected power.
    }
    
    @Column {
        ![A screenshot of the power picker user interface with four powers displayed – ice, fire, wind, and lightning](slothy-powerPicker)
    }
}

@Row {
    @Column {
        ![A screenshot of the sloth status user interface that indicates the the amount of sleep, fun, and exercise a given sloth is in need of.](slothy-status)
    }
    
    @Column(size: 2) {
        Once you've customized your sloth, it's ready to ready to thrive.
        You'll find that sloths will happily munch on a leaf, but may not be as 
        receptive to working out. Use the activity picker to send some
        encouragement.
    }
}
Creating a tab navigator markdown · at 18:16 ↗
@TabNavigator {
    @Tab("English") {
        ![Two screenshots showing the Slothy app rendering with English language content. The first screenshot shows a sloth map and the second screenshot shows a sloth power picker.](slothy-localization_eng)
    }
    
    @Tab("Chinese") {
        ![Two screenshots showing the Slothy app rendering with Chinese language content. The first screenshot shows a sloth map and the second screenshot shows a sloth power picker.](slothy-localization_zh)
    }
    
    @Tab("Spanish") {
        ![Two screenshots showing the Slothy app rendering with Spanish language content. The first screenshot shows a sloth map and the second screenshot shows a sloth power picker.](slothy-localization_es)
    }
}
Adding a video markdown · at 19:07 ↗
@Video(poster: "slothy-hero-poster", source: "slothy-hero", alt: "An animated video showing two screens in the Slothy app. The first screenshot shows a sloth map and the second screenshot shows a sloth power picker.")
Specifying a page's "Call to Action" link markdown · at 19:50 ↗
@Metadata {
    @CallToAction(purpose: link, url: "https://example.com/slothy-repository")
}
Specifying a page's kind as "Sample Code" markdown · at 20:29 ↗
@Metadata {
    @CallToAction(purpose: link, url: "https://example.com/slothy-repository")
    @PageKind(sampleCode)
}
Using the "Links" directive to feature content markdown · at 21:55 ↗
@Links(visualStyle: detailedGrid) {
    - <doc:GettingStarted>
    - <doc:SlothySample>
}
Specifying a page's card image markdown · at 22:55 ↗
@Metadata {
    @PageImage(
        purpose: card, 
        source: "slothy-card", 
        alt: "Two screenshots showing the Slothy app. The first screenshot shows a sloth map and the second screenshot shows a sloth power picker.")
}
Specifying a page's icon image markdown · at 23:41 ↗
@Metadata {
    @PageImage(
        purpose: icon, 
        source: "slothCreator-icon", 
        alt: "A technology icon representing the SlothCreator framework.")
}
Specifying a page's color markdown · at 23:42 ↗
@Metadata {
    @PageColor(green)
}
theme-settings.json json · at 27:04 ↗
{
    "theme": {
        "color": {
            "standard-green": "#83ac38"
        },
        "typography": {
            "html-font": "serif"
        }
    }
}

Resources

  • [documentation] DocC