16

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.

algal
  • 27,584
  • 13
  • 78
  • 80
  • Seems relevant: http://stackoverflow.com/questions/24296470/how-do-i-import-a-swift-function-declared-in-a-compiled-swiftmodule-into-anothe/24396175#comment42764530_24396175 – algal Nov 25 '14 at 17:39

1 Answers1

5

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.

DennyLou
  • 313
  • 2
  • 4
  • 2
    This doesn't work. It doesn't list frameworks or modules that I _can_ import, but instead the shared libraries that have _already_ been loaded, which is not very useful. For instance, I can import CoreGraphics by doing "import CoreGraphics", but the words "CoreGraphics" don't appear anywhere in that list. – algal Nov 19 '14 at 11:40
  • No pb @algal it's all good. I'll investigate a bit more and see if I can be of any help. Yours it's a very good question. And with Swift we're all slightly brand new so, the more we help each other the better ;P – DennyLou Nov 19 '14 at 22:13