I have an SPM package hosted at https://github.com/janodev/foobar
.
How can I generate documentation with Docc and host it at GitHub?
CodePudding user response:
- Install Xcode 13.3 beta or later.
- Add Swift-DocC as a dependency of your package. It will look similar to this:
let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", branch: "main"),
],
targets: [
// ...
]
)
- Enable page publishing in GitHub
- In your GitHub repository go to Settings > Pages
- Select Branch:main, folder: /docs
- Click Save
- Generate docs in the directory
./docs
.
# note this is for GitHub hosting, with a specific target and base path 'Foobar'
swift package \
--allow-writing-to-directory ./docs \
--target Foobar \
generate-documentation \
--output-path ./docs \
--transform-for-static-hosting \
--hosting-base-path Foobar
- Push the generated documentation to the repo.
The site will appear at https://janodev.github.io/foobar/documentation/foobar
Xcode 13.3 provides Swift 5.6, required by Swift-DocC, and the ability to use DocC for iOS applications. However, Swift-DocC doesn’t seem to work with apps as of this writing. I even tried writing a fake package and passing the usual compiler flags to compile UIKit in the terminal (see below). Likely this will be supported in a future release.
-Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios15.2-simulator"
CodePudding user response:
To accomplish Jano answer:
there are also some good and useful documentation from swift.org about it:
here tells you how to build documentation using DocC:
https://www.swift.org/documentation/docc/building-an-interactive-tutorial
and here tells you how to distribute your documentation to others:
https://www.swift.org/documentation/docc/distributing-documentation-to-other-developers