8

From the first beta of Swift, we have been able to see the Swift interface for a module through an interactive process. You start with a Swift file in an Xcode project, right-click on a symbol, and choose "Jump to Definition"; Xcode will generate a file with the declaration.

That procedure is a bit tedious. It's very manual; you have to start with a Swift file in an Xcode project; and you have to know the name of the symbol in advance. It doesn't generate all the declarations in the module — if the module was defined in Objective-C, it only shows declarations from a single .h file.

I learned about the command-line tool swift-ide-test in Beta 3 via http://www.jpsim.com/uncovering-sourcekit/. By using a command like the following, I could generate the declarations for an entire framework:

xcrun swift-ide-test -print-module -source-filename /dev/null \
    -sdk /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk \
    -print-regular-comments -module-print-submodules -module-to-print CoreGraphics

However, in Beta 4 the swift-ide-test command has disappeared.

Does anyone know the new way to automatically generate Swift declarations via the command line?

Jay Lieske
  • 4,788
  • 3
  • 30
  • 41
  • That question is petty close — the answer there prints out a single declaration, the one here prints out a module. – Jay Lieske Aug 18 '14 at 05:14

1 Answers1

4

I figured out a technique, based on a blog post by Erica Sadun (http://ericasadun.com/2014/07/28/swift-docs-generation/).

The Swift REPL has a :print_module command that dumps all the declarations in the module. Unlike choosing a module in Xcode, it doesn't stop at just one (virtual) header.

So this command will print out all the declarations in CoreGraphics:

echo ":print_module CoreGraphics" | xcrun swift -deprecated-integrated-repl
Jay Lieske
  • 4,788
  • 3
  • 30
  • 41