Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically generate the Swift interface for a compiled module [duplicate]

Tags:

swift

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?

like image 382
Jay Lieske Avatar asked Jul 28 '14 22:07

Jay Lieske


1 Answers

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
like image 104
Jay Lieske Avatar answered Nov 15 '22 04:11

Jay Lieske