Article
Xcode Integration
Generate static documentation from Xcode projects and workspaces.
Overview
While the Static Documentation Plugin is designed for Swift packages, you can also use it with Xcode projects that contain Swift packages or use Swift Package Manager for dependencies.
Swift Packages in Xcode
If your Xcode project uses a Swift package (either local or as a dependency), you can generate documentation from the command line:
cd /path/to/your/package
swift package generate-static-documentation --output ./docs
Build Phase Integration
Add a Run Script build phase to generate documentation during builds:
-
Select your target in Xcode
-
Go to Build Phases
-
Click + and select New Run Script Phase
-
Add the script:
if [ "$CONFIGURATION" = "Release" ]; then
cd "$SRCROOT"
swift package generate-static-documentation --output "$BUILT_PRODUCTS_DIR/Documentation"
fi
This generates documentation only for Release builds.
Custom Build Rules
For more control, create a custom build rule:
-
Select your target
-
Go to Build Rules
-
Click + to add a rule
-
Configure:
-
Process: Source files with names matching
*.docc -
Using: Custom script
-
Xcode Cloud
For Xcode Cloud workflows, add a post-clone script:
Create ci_scripts/ci_post_clone.sh:
#!/bin/bash
set -e
# Install dependencies
brew tap mipalgu/tap
brew install swift-docc-static
# Generate documentation
cd "$CI_PRIMARY_REPOSITORY_PATH"
docc-static generate --output ./docs
Make the script executable:
chmod +x ci_scripts/ci_post_clone.sh
Documentation Viewer
After generating documentation, you can:
-
Open directly: Double-click
index.htmlin Finder -
Use Quick Look: Select the docs folder and press Space
-
Add to Xcode: Drag the docs folder into your project navigator
Alternative: Using docc-static Directly
If you prefer not to modify your Xcode project, use the command-line tool directly:
# Install
brew tap mipalgu/tap
brew install swift-docc-static
# Generate from your package directory
cd /path/to/package
docc-static generate --output ~/Desktop/docs
# Open
open ~/Desktop/docs/index.html
Troubleshooting
“Package not found” Error
Ensure you’re in the directory containing Package.swift:
cd /path/to/your/package
ls Package.swift # Should show the file
swift package generate-static-documentation
Build Failures
If the plugin fails to build your package:
-
Ensure the package builds successfully:
swift build -
Check for Swift version compatibility:
swift --version -
Try with verbose output:
swift package generate-static-documentation --verbose
Missing Dependencies
If dependencies aren’t resolved:
swift package resolve
swift package generate-static-documentation
See Also
Related Documentation
Add the SPM plugin to your package for integrated documentation generation.
Configure documentation generation with command-line options.