Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From the Swift REPL, how do I get a list of available modules?

Tags:

swift

From the Swift REPL, I can import framework modules like Foundation by doing import Foundation.

What command can I give on the REPL that will produce a list of all the modules which are available to be imported?

ADDENDUM:

Just to be really clear what I'm trying to understand. On the REPL, if I type the words "import Foundation" then I can access the Foundation types, constants, etc.. If I type the words "import CoreGraphics" then I can access CoreGraphics. If I have the 3rd party library OptionKit installed, then typing "import OptionKit" lets me use OptionKit. These are all modules which can be directly imported from the REPL.

Some modules or frameworks, however, cannot. For instance, if I type "import ParseOSX" from the REPL, I get an error, even though it is possible to do "import ParseOSX" from a standalone script.

What I want to understand is just, how do I determine the list of frameoworks or modules which I can import, from the REPL, by using the import command.

ADDENDUM2:

I've done a little searching and it seems like the only 3rd-party framework I've successfully imported from /Library/Frameworks, OptionKit, is also the only one with a .swiftmodule file. And all the importable Apple frameworks seem to have their own .swiftmodule files, which you can find by searching under /Application/Xcode.app.

So this suggests you can import at runtime only the framework with .swiftmodule files. But I'm not sure of this.

like image 333
algal Avatar asked Nov 12 '14 08:11

algal


People also ask

How does Swift REPL work?

The Swift REPL allows you to import the core libraries like Foundation , Dispatch and system modules like Darwin on macOS and Glibc on Linux. In fact, the REPL allows you to import any Swift module as long as it can correctly find and load them using the compiler arguments that are provided while launching the REPL.

How do modules work in Swift?

A module is a single unit of code distribution—a framework or application that's built and shipped as a single unit and that can be imported by another module with Swift's import keyword. Each build target (such as an app bundle or framework) in Xcode is treated as a separate module in Swift.


1 Answers

If you're looking simply for the list, you might want to use:

:target modules list 

That returns the full list of modules. Hope this help.

like image 110
DennyLou Avatar answered Sep 19 '22 09:09

DennyLou