Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submodules in Swift

Tags:

module

swift

Say I have an app, MyApp which is built in an Xcode workspace. Inside this workspace I have the primary app target and two nested Xcode projects for my frameworks, Foo and Bar.

Inside my app I import Foo and Bar and dependency inject an object in Foo into an object in Bar. Say, however, I don't need all of Foo, just a couple of classes. How could I create a submodule within foo and import that. E.g. import Foo.Models.Animals.Dog

like image 885
AttilaTheFun Avatar asked Jul 25 '15 10:07

AttilaTheFun


1 Answers

While you can do something like

import struct MyModule.MyStruct

import func Darwin.glob

I'm not sure if you can get much deeper than that. Here's a relevant quote from the (free) Swift book

“Providing more detail limits which symbols are imported—you can specify a specific submodule or a specific declaration within a module or submodule. When this detailed form is used, only the imported symbol (and not the module that declares it) is made available in the current scope.”

It goes on to explain that you can import any of typealias, struct, class, enum, protocol, var, or func

It looks as though Swift has some type of support for submodules (they're mentioned offhand a few places), but I'm not sure we have the ability to actually compile those just yet.

like image 169
bppr Avatar answered Oct 10 '22 22:10

bppr