如何在 Swift 中使用命名空间? [英] How to use Namespaces in Swift?

查看:50
本文介绍了如何在 Swift 中使用命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档只提到了嵌套类型,但不清楚它们是否可以用作命名空间.我没有发现任何明确提及命名空间.

The documentation only mentions nested types, but it's not clear if they can be used as namespaces. I haven't found any explicit mentioning of namespaces.

推荐答案

尽管可以使用 Framework 和 Libraries 实现命名空间,但最好的解决方案是使用 Swift Package Manager 使用本地包.除了具有访问修饰符之外,这种方法还有其他一些好处.就像在 Swift Package Manager 中一样,文件是基于目录系统而不是目标成员进行管理的,您不必为团队合作中经常出现的合并冲突而烦恼.此外,无需设置文件成员资格.

Even though it is possible to implement namespaces using Framework and Libraries but the best solution is to use local packages using Swift Package Manager. Besides having access modifiers, this approach has some other benefits. As in Swift Package Manager, the files are managed based on the directory system, not their target member ship, you won't have to struggle with merge conflicts that arise frequently in teamworks. Furthermore, there is no need to set file memberships.

要检查如何使用本地 Swift 包,请参阅以下链接:使用本地包组织代码

To check how to use local Swift packages refer to the following link: Organizing Your Code with Local Packages

这篇关于如何在 Swift 中使用命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆