Soulful docs for Swift & Objective-C
jazzy is a command-line utility that generates documentation for Swift or Objective-C
Both Swift and Objective-C projects are supported.
Instead of parsing your source files, jazzy hooks into [Clang][clang] and
[SourceKit][sourcekit] to use the [AST][ast] representation of your code and
its comments for more accurate results. The output matches the look and feel
of Apple’s official reference documentation, post WWDC 2014.
Jazzy can also generate documentation from compiled Swift modules using their symbol graph instead of source code.
This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].
You need development tools to build the project you wish to document. Jazzy supports both [Xcode][xcode] and [Swift Package Manager][spm] projects.
Jazzy expects to be running on macOS. See below for tips to run Jazzy on Linux.
[sudo] gem install jazzySee Installation Problems for solutions to some common problems.
Run jazzy from your command line. Run jazzy -h for a list of additional options.
If your Swift module is the first thing to build, and it builds fine when running
xcodebuild or swift build without any arguments from the root of your project, then
just running jazzy (without any arguments) from the root of your project should
succeed too!
If Jazzy generates docs for the wrong module then use --module to tell it which
one you'd prefer. If this doesn't help, and you're using Xcode, then try passing
extra arguments to xcodebuild, for example
jazzy --build-tool-arguments -scheme,MyScheme,-target,MyTarget.
If you want to generate docs for several modules at once then see Documenting multiple modules.
You can set options for your project’s documentation in a configuration file,
.jazzy.yaml by default. For a detailed explanation and an exhaustive list of
all available options, run jazzy --help config.
Swift documentation is written in markdown and supports a number of special keywords. Here are some resources with tutorials and examples, starting with the most modern:
For Objective-C documentation the same keywords are supported, but note that the format
is slightly different. In Swift you would write - returns:, but in Objective-C you write @return. See Apple's HeaderDoc User Guide for more details. Note: jazzy currently does not support all Objective-C keywords listed in this document, only @param, @return, @warning, @see, @note, @code, @endcode, and @c.
Jazzy can also generate cross-references within your documentation. A symbol name in backticks generates a link, for example:
MyClass.method from the documentation of another
method or property in the same class.Jazzy understands Apple's DocC-style links too, for example:
method(param1:) in the rendered page.method(_:).
Jazzy can't tell which overload you intend and links to the first one.If your documentation is for multiple modules then symbol name resolution works approximately as though all the modules have been imported: you can use `TypeName` to refer to a top-level type in any of the modules, or `ModuleName.TypeName` to be specific. If there is an ambiguity then you can use a leading slash to indicate that the first part of the name should be read as a module name: `/ModuleName.TypeName`.
Jazzy can render math equations written in LaTeX embedded in your markdown:
`$equation$` renders the equation in an inline style.`$$equation$$` renders the equation in a display style, centered on a
line of its own.For example, the markdown:
Inline: `$ax^2+bx+c=0$`
Block: `$$x={\frac {-b\pm {\sqrt {b^{2}-4ac}}}{2a}}$$`..renders as:
Math support is provided by KaTeX.
Swift documentation is generated by default.
This is how Realm Swift docs are generated:
jazzy \
--clean \
--author Realm \
--author_url https://realm.io \
--source-host github \
--source-host-url https://github.com/realm/realm-cocoa \
--source-host-files-url https://github.com/realm/realm-cocoa/tree/v0.96.2 \
--module-version 0.96.2 \
--build-tool-arguments -scheme,RealmSwift \
--module RealmSwift \
--root-url https://realm.io/docs/swift/0.96.2/api/ \
--output docs/swift_output \
--theme docs/themesThis is how docs are generated for a project that uses the Swift Package Manager:
jazzy \
--module DeckOfPlayingCards \
--swift-build-tool spm \
--build-tool-arguments -Xswiftc,-swift-version,-Xswiftc,5To generate documentation for a simple Objective-C project, you must pass the following parameters:
--objc--umbrella-header ...--framework-root ......and optionally:
--sdk [iphone|watch|appletv][os|simulator]|macosx (default value
of macosx)--hide-declarations [objc|swift] (hides the selected language declarations)For example, this is how the AFNetworking docs are generated:
jazzy \
--objc \
--author AFNetworking \
--author_url http://afnetworking.com \
--source-host github \
--source-host-url https://github.com/AFNetworking/AFNetworking \
--source-host-files-url https://github.com/AFNetworking/AFNetworking/tree/2.6.2 \
--module-version 2.6.2 \
--umbrella-header AFNetworking/AFNetworking.h \
--framework-root . \
--module AFNetworkingFor a more complicated Objective-C project, instead use --build-tool-arguments
to pass arbitrary compiler flags. For example, this is how Realm Objective-C
docs are generated:
jazzy \
--objc \
--clean \
--author Realm \
--author_url https://realm.io \
--source-host github \
--source-host-url https://github.com/realm/realm-cocoa \
--source-host-files-url https://github.com/realm/realm-cocoa/tree/v2.2.0 \
--module-version 2.2.0 \
--build-tool-arguments --objc,Realm/Realm.h,--,-x,objective-c,-isysroot,$(xcrun --show-sdk-path),-I,$(pwd) \
--module Realm \
--root-url https://realm.io/docs/objc/2.2.0/api/ \
--output docs/objc_output \
--head "$(cat docs/custom_head.html)"See the Objective-C docs for more information and some tips on troubleshooting.
This feature has some rough edges.
To generate documentation for a mixed Swift and Objective-C project you must first generate two [SourceKitten][sourcekitten] files: one for Swift and one for Objective-C.
Then pass these files to Jazzy together using --sourcekitten-sourcefile.
This is how docs are generated from an Xcode project for a module containing both Swift and Objective-C files:
# Generate Swift SourceKitten output
sourcekitten doc -- -workspace MyProject.xcworkspace -scheme MyScheme > swiftDoc.json
# Generate Objective-C SourceKitten output
sourcekitten doc --objc $(pwd)/MyProject/MyProject.h \
-- -x objective-c -isysroot $(xcrun --show-sdk-path --sdk iphonesimulator) \
-I $(pwd) -fmodules > objcDoc.json
# Feed both outputs to Jazzy as a comma-separated list
jazzy --module MyProject --sourcekitten-sourcefile swiftDoc.json,objcDoc.json.swiftmodules or frameworksSwift 5.3 added support for symbol graph generation from .swiftmodule files.
Jazzy can use this to generate API documentation. This is faster than using
the source code directly but does have limitations: for example documentation
comments are available only for public declarations, and the presentation of
Swift extensions may not match the way they are written in code.
Some examples:
jazzy --module Combine --swift-build-tool symbolgraphjazzy --module Combine --swift-build-tool symbolgraph
--sdk iphoneos
--build-tool-arguments -target,arm64-apple-ios14.1target is the LLVM target triple and needs to match the SDK. The
default here is the target of the host system that Jazzy is running on,
something like x86_64-apple-darwin19.6.0..swiftmodule:jazzy --module MyMod --swift-build-tool symbolgraph
--build-tool-arguments -I,/Build/Products/Build/Products/MyMod.swiftmodule exists. Jazzy's
--source-directory (default current directory) is searched by default,
so you only need the -I override if that's not enough.jazzy --module MyMod --swift-build-tool symbolgraph
--build-tool-arguments -F,/Build/Products/Build/Products/MyMod.framework exists and contains
a .swiftmodule. Again the --source-directory is searched by default
if -F is not passed in.jazzy --module MyMod --swift-build-tool symbolgraph
--symbolgraph-directory Build/symbolgraphs-emit-symbol-graph, you can pass the location of these files using
--symbolgraph-directory from where they can be parsed directly.See swift symbolgraph-extract -help for all the things you can pass via
--build-tool-arguments: if your module has dependencies then you may need
to add various search path options to let Swift load it.
This feature is new, bugs and feedback welcome
Sometimes it's useful to document multiple modules together in the same site, for example an app and its extensions, or an SDK that happens to be implemented as several modules.
Jazzy can build docs for all these together and create a single site with search, cross-module linking, and navigation.
If all the modules share the same build flags then the easiest way to do this
is with --modules, for example jazzy --modules ModuleA,ModuleB,ModuleC.
If your modules have different build flags then you have to use the config file. For example:
modules:
- module: ModuleA
- module: ModuleB
build_tool_arguments:
- -scheme
- SpecialScheme
- -targetjazzy 0.15.4 fails at startup with mustache 1.1.3: `undefined method 'map' for an instance of Pathname`
Can't leverage github action variables due to config file requirement
@name in single line comment is parsed incorrectly
Use inherited docs when local ones are missing
Generate Sitemap
Multi-framework Doc Generation for Obj-C
Drop raw values from declarations
Parameter not included when using swift style commenting with obj-c
Break up autolinking of generic types.
Custom categories from code comments