Include Swift info for Obj-C symbols from command line

I've found the Xcode option DOCC_EXTRACT_SWIFT_INFO_FOR_OBJC_SYMBOLS, which looks like it would extract Swift documentation for Objective C code resulting in the language picker being available in the generated docs.

I need to replicate this behaviour when generating docs outside of Xcode using
xcrun clang -extract-api
and
xcrun docc convert

I'm guessing there's an option that needs to be passed to clang to fetch the Swift symbol info for ObjC classes but I can't find it. Currently my ObjC class with NS_SWIFT_NAME attributes only generates ObjC documentation. Any pointers please?

clang -extract-api only generates symbol graphs from Clang's point of view. If you want to get Swift versions of the symbol graphs, you'll need to run xcrun swift-symbolgraph-extract with the appropriate flags for your project.

For example:

xcrun swift-symbolgraph-extract -target arm64-apple-macos -F /path/to/framework -module-name MyFramework -output-dir /path/to/symbol-graphs

-module-name, -target, and -output-dir are required, and -I and -F can be used to give it the appropriate include paths to search. -sdk can also be given with a path (e.g. via xcrun --sdk macosx --show-sdk-path) if your project is linking against a specific Xcode SDK. swift-symbolgraph-extract -help lists all the available flags you can give it.

1 Like