Swift-DocC is a documentation compiler for Swift frameworks and packages aimed
at making it easy to write and publish great developer documentation.
Swift-DocC is being actively developed. For more information about the
Swift-DocC project, see the introductory blog post
The Swift Forums are
the best place to get help with Swift-DocC and discuss future plans.
Technical Overview and Related Projects
Swift-DocC builds documentation by combining Symbol Graph files containing API information
.docc Documentation Catalog containing articles and tutorials
to create a final archive containing the compiled documentation.
More concretely, Swift-DocC understands the following kinds of inputs:
Symbol Graph files with the
Symbol Graph files are a machine-readable representation of a module’s APIs,
including their documentation comments and relationship with one another.
A Documentation Catalog with the
Documentation Catalogs can include additional documentation content like the following:
Documentation markup files with the
.mdextension. Documentation markup files can
be used to extend documentation for symbols and to write free-form articles.
Tutorial files with the
.tutorialextension. Tutorial files are used to author
step-by-step instructions on how to use a framework.
Additional documentation assets with known extensions like
Info.plistfile containing metadata such as the name of the documented module.
This file is optional and the information it contains can be passed via the command line.
Swift-DocC outputs a machine-readable archive of the compiled documentation.
This archive contains render JSON files, which fully describe the contents
of a documentation page and can be processed by a renderer such as
For more in-depth technical information about Swift-DocC, you
can build and preview the project’s technical documentation
from the command line with
preview-docsscript expects the
variable to be set with the path to a Swift-DocC renderer. See the
doccto build and preview documentation
section below for details.
Alternatively, you can open the package in Xcode 13 and select the “Build Documentation”
button in the Product menu to view the documentation in Xcode’s documentation window.
As of Swift 5.5, the Swift Compiler is able to
emit Symbol Graph files as part of the compilation process.
SymbolKit is a Swift package containing
the specification and reference model for the Symbol Graph File Format.
Swift Markdown is a
Swift package for parsing, building, editing, and analyzing
Markdown documents. It includes support for the Block Directive elements
that Swift-DocC’s tutorial files rely on.
is a web application that understands and renders
Swift-DocC’s render JSON format.
Xcode consists of a suite of
tools that developers use to build apps for Apple platforms.
Beginning with Xcode 13, Swift-DocC is integrated into Xcode
with support for building and viewing documentation for your framework and
Getting Started with
docc is the command line interface (CLI) for Swift-DocC and provides
support for converting and previewing DocC documentation.
DocC is a Swift package. If you’re new to Swift package manager,
the documentation here
provides an explanation of how to get started and the software you’ll need
DocC requires Swift 5.5 which is included in Xcode 13.
Checkout this repository using:
git clone https://github.com/apple/swift-docc.git
Navigate to the root of the repository with:
Finally, build DocC by running:
docc, run the following command:
swift run docc
Installing into Xcode
You can test a locally built version of Swift-DocC in Xcode 13 or later by setting
DOCC_EXEC build setting to the path of your local
Select the project in the Project Navigator.
In the Build Settings tab, click ‘+’ and then ‘Add User-Defined Setting’.
Create a build setting
DOCC_EXECwith the value set to
The next time you invoke a documentation build with the “Build Documentation”
button in Xcode’s Product menu, your custom
docc will be used for the build.
You can confirm that your custom
docc is being used by opening the latest build
log in Xcode’s report navigator and expanding the “Compile documentation” step.
docc to build and preview documentation
You can use
docc directly to build documentation for your Swift framework
or package. The below instructions use this repository as an example, but
apply to any Swift package. Just replace any reference to
with the name of your package.
1. Generate a symbol graph file
Begin by navigating to the root of your Swift package.
Then run the following to generate Symbol Graph files for your target:
mkdir -p .build/symbol-graphs && \ swift build --target SwiftDocC \ -Xswiftc -emit-symbol-graph \ -Xswiftc -emit-symbol-graph-dir -Xswiftc .build/symbol-graphs
You should now have a number of
.symbols.json files in
representing the provided target and its dependencies. You can copy out the files representing
just the target itself with:
mkdir .build/swift-docc-symbol-graphs \ && mv .build/symbol-graphs/SwiftDocC* .build/swift-docc-symbol-graphs
2. Set the path to your renderer
The best place to get started with Swift-DocC-Render is with the
instructions in the project’s README.
If you have Xcode 13 installed, you can use the version of Swift-DocC-Render
that comes included in Xcode (instead of building a copy locally) with:
export DOCC_HTML_DIR="$(dirname $(xcrun --find docc))/../share/docc/render"
Alternatively, you can clone Swift-DocC-Render and build a local
copy of the renderer with these instructions:
requires Node.js v14.
git clone https://github.com/apple/swift-docc-render.git cd swift-docc-render npm install npm run build
Then point the
DOCC_HTML_DIR environment variable
to the generated
3. Preview your documentation
docc preview command performs a conversion of your documentation and
starts a local web server to allow for easy previewing of the built documentation.
It monitors the provided Documentation Catalog for changes and updates the preview
as you’re working.
docc preview Sources/SwiftDocC/SwiftDocC.docc \ --fallback-display-name SwiftDocC \ --fallback-bundle-identifier org.swift.SwiftDocC \ --fallback-bundle-version 1.0.0 \ --additional-symbol-graph-dir .build/swift-docc-symbol-graphs
You should now see the following in your terminal:
Input: ~/Developer/swift-docc/Sources/SwiftDocC/SwiftDocC.docc Template: ~/Developer/swift-docc-render/dist ======================================== Starting Local Preview Server Address: http://localhost:8000/documentation/swiftdocc ======================================== Monitoring ~/Developer/swift-docc/Sources/SwiftDocC/SwiftDocC.docc for changes...
And if you navigate to http://localhost:8000/documentation/swiftdocc you’ll see
the rendered documentation for
Swift-DocC’s CLI tool (
docc) will be integrated into the Swift toolchain
and follows the Swift compiler’s versioning scheme.
SwiftDocC library is versioned separately from
SwiftDocC is under
active development and source stability is not guaranteed.
Bug Reports and Feature Requests
Submitting a Bug Report
Note: You can use the
in this repository to gather helpful environment information to paste
into your bug report by running the following:bin/environment
If you can confirm that the bug occurs when using the latest commit of Swift-DocC
main branch (see Building Swift-DocC),
that will help us track down the bug faster.
Submitting a Feature Request
Don’t hesitate to submit a feature request if you see a way
Swift-DocC can be improved to better meet your needs.
All user-facing features must be discussed
in the Swift Forums
before being enabled by default.
Contributing to Swift-DocC
Please see the contributing guide for more information.