Automatically create a Swift interface for a compiled module

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

This procedure is a bit tedious. This is a very guide; You should start with a Swift file in your Xcode project; and you must know the name of the symbol in advance. It does not generate all declarations in the module — if the module was defined in Objective-C, it only displays declarations from a single .h file.

I learned about the command line swift-ide test tool in Beta 3 through http://www.jpsim.com/uncovering-sourcekit/ . Using the following command, I could generate declarations for the entire structure:

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 quick pick-fade command disappeared.

Does anyone know a new way to automatically create Swift declarations through the command line?

+6
source share
1 answer

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

Swift REPL has a command :print_module , which flushes all declarations in the module. Unlike module selection in Xcode, it does not stop at just one (virtual) header.

Thus, this command will print all ads in CoreGraphics:

 echo ":print_module CoreGraphics" | xcrun swift -deprecated-integrated-repl 
+2
source

Source: https://habr.com/ru/post/972997/


All Articles