Swift中的子模块 [英] Submodules in Swift
问题描述
说我有一个应用程序MyApp,它构建在Xcode工作区中.在此工作区中,我有主要的应用程序目标和两个嵌套的Xcode项目,分别用于Foo和Bar.
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.
在我的应用程序内部,我导入Foo和Bar,然后依赖项将Foo中的对象注入Bar中的对象.说,但是,我不需要全部的Foo,仅需要几节课.我如何在foo中创建一个子模块并将其导入.例如.导入Foo.Models.Animals.Dog
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
推荐答案
尽管您可以做类似的事情
import struct MyModule.MyStruct
import func Darwin.glob
我不确定你是否能比这更深入.这是(免费)Swift书
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."
它继续说明您可以导入typealias
,struct
,class
,enum
,protocol
,var
或func
It goes on to explain that you can import any of typealias
, struct
, class
, enum
, protocol
, var
, or func
Swift似乎对子模块提供了某种类型的支持(在某些地方被提及),但是我不确定我们是否能够实际编译这些子模块.
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.
这篇关于Swift中的子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!