本文介绍了如何在Swift中创建可导入模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通读了Apple的Swift文档,却对如何创建模块或如何将类或结构成员定义为私有或公共一无所知.

I have read through Apple's documentation for Swift and can find nothing about how to create modules or how to define class or stucture members as private or public.

语法中有对import语句的引用,但是我找不到有关它的用途或使用方法的信息.

There are references to the import statement in the syntax but I can find no information on what it does or how to use it.

有人知道我在哪里可以找到这个吗?

Does anyone know where I can find this?

推荐答案

更新

您可以使用框架对快速项目进行模块化.

You can modularize a swift project using frameworks.

我们通过为每个模块创建单独的框架项目并通过Xcode工作区将它们链接来进行模块化.当我们将组件分成不同的项目时,它看起来更加自然.它还可以确保模块之间只有单向通信.开发人员可以在隔离上进行工作/测试,而无需考虑其他模块.

We modularize by creating separate framework projects for each module and link them via Xcode workspace. It looks more natural when we separate the components into different projects & it also makes sure that there is only a one-way communication between modules. Developers can work/test on isolation without thinking much about other modules.

默认情况下,在框架中创建的类/结构/等将具有internal访问控制类型,因此仅在模块中可见.为了使其在模块外部可见,可以将其设置为public.

By default classes/structs/etc created within a framework will have an internal access control type so it is only visible within the modules. In order to make it visible outside the module, you can make it public.

有关访问控制级别的更多信息,请此处

More info on access controll level here

最新的Xcode 6 beta更新(beta 4)使访问控制变得迅速

The latest Xcode 6 beta update (beta 4) bring access control to swift

快速访问控制具有三个访问级别:

Swift access control has three access levels:

  • 私有实体只能在定义它们的源文件中访问.
  • 可以在定义目标的任何位置访问
  • 内部实体. 可以从目标内的任何位置以及导入当前目标模块的任何其他上下文中访问
  • 公共实体.
  • private entities can only be accessed from within the source file where they are defined.
  • internal entities can be accessed anywhere within the target where they are defined.!
  • public entities can be accessed from anywhere within the target and from any other context that imports the current target’s module.

这篇关于如何在Swift中创建可导入模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:58