Submodules in Swift

Let's say I have a MyApp application that is built into the Xcode workspace. Inside this workspace, I have the main purpose of the application and two nested Xcode projects for my frameworks, Foo and Bar.

In my application, I import Foo and Bar and the dependent injection of the object in Foo into the object in Bar. Say, however, I do not need all of Foo, just a few classes. How can I create a submodule inside foo and import it. For instance. import Foo.Models.Animals.Dog

+5
source share
1 answer

While he can do something like

import struct MyModule.MyStruct import func Darwin.glob 

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

"By providing more detailed restrictions that are imported, you can specify a specific submodule or specific declaration in a module or submodule. When this detailed form is used, only the imported symbol (and not the module that declares it) is available in the current scope."

The following explains that you can import any of typealias , struct , class , enum , protocol , var or func

It seems that Swift has some support for submodules (they are mentioned in several places), but I'm not sure that we have the ability to actually compile them yet.

+7
source

All Articles