5

I want to check a public content of a .swiftmodule file from an iOS framework.

Here (https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160111/000827.html) I've found a suggestion to use swift-ide-test:

You can use the swift-ide-test tool to dump the public interface for a module, but the command-line interface is less pretty than it should be:

swift-ide-test -print-module -source-filename=dummy.swift -module-to-print=MyApp

…plus any -I or -F paths necessary to find your module and all its dependencies. If you're on a Mac, you'll need to insert "xcrun -sdk macosx" or "xcrun -sdk iphoneos" at the start to find the system headers.

Unfortunately, when I try to run xcrun -sdk iphoneos swift-ide-test with Xcode 10.1, I get following error:

$ xcrun -sdk iphoneos swift-ide-test
xcrun: error: unable to find utility "swift-ide-test", not a developer tool or in PATH

Seems that this tool was removed from Xcode.

Any other ideas on how to open a .swiftmodule file?

Anton Malmygin
  • 3,406
  • 2
  • 25
  • 31

3 Answers3

8

After few hours of struggling, I've found an IMPLICIT way of checking a public content of modules from an iOS framework.

The trick is done by using :print_module command inside the Swift REPL.

More precisely, you need to launch Swift REPL with a path to your framework:

swift -F <path to a folder with LibName.framework> -deprecated-integrated-repl

Now you can use :print_module command with a name of your framework:

(swift) :print_module LibName

Sources:

https://stackoverflow.com/a/27882120/2241008

https://stackoverflow.com/a/25005445/2241008

https://stackoverflow.com/a/36235186/2241008

P.S. swift sources still have a source code for swift-ide-test tool (https://github.com/apple/swift/tree/master/tools/swift-ide-test), so another way to see contents of swiftmodules will be in compiling this tool, but I did not investigated this solution any further.

Anton Malmygin
  • 3,406
  • 2
  • 25
  • 31
  • 1
    Seem to no longer work: `Compiler-internal integrated REPL has been removed; use the LLDB-enhanced REPL instead.` – Rasty Sep 09 '22 at 19:18
2

As mentioned on the Swift forums, you can get a textual representation of a swift module using the command llvm-bcanalyzer -dump. You can install this using brew install llvm and the man page is here.

Patrick Beard
  • 592
  • 6
  • 11
1

Open a .swiftmodule file

[.swiftmodule]

You are able to:

  1. add this framework into framework
  2. import the framework import <module_name>
  3. Jump to Definition
yoAlex5
  • 29,217
  • 8
  • 193
  • 205