Swift 中的子模块
Submodules in Swift
假设我有一个应用程序 MyApp,它是在 Xcode 工作区中构建的。在这个工作区内,我有主要的应用程序目标和两个嵌套的 Xcode 框架项目,Foo 和 Bar。
在我的应用程序中,我导入了 Foo 和 Bar,然后依赖项将 Foo 中的一个对象注入到 Bar 中的一个对象中。但是,我不需要所有的 Foo,只需要几个 类。我如何在 foo 中创建一个子模块并将其导入。例如。导入 Foo.Models.Animals.Dog
虽然你可以做类似
的事情
import struct MyModule.MyStruct
import func Darwin.glob
我不确定你是否能比这更深入。这是来自 (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
、[=16=中的任何一个],或func
看起来 Swift 对子模块有某种类型的支持(它们在一些地方被提及),但我不确定我们是否有能力实际编译这些。
假设我有一个应用程序 MyApp,它是在 Xcode 工作区中构建的。在这个工作区内,我有主要的应用程序目标和两个嵌套的 Xcode 框架项目,Foo 和 Bar。
在我的应用程序中,我导入了 Foo 和 Bar,然后依赖项将 Foo 中的一个对象注入到 Bar 中的一个对象中。但是,我不需要所有的 Foo,只需要几个 类。我如何在 foo 中创建一个子模块并将其导入。例如。导入 Foo.Models.Animals.Dog
虽然你可以做类似
的事情import struct MyModule.MyStruct
import func Darwin.glob
我不确定你是否能比这更深入。这是来自 (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
、[=16=中的任何一个],或func
看起来 Swift 对子模块有某种类型的支持(它们在一些地方被提及),但我不确定我们是否有能力实际编译这些。