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

查看:256
本文介绍了如何在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.

推荐答案

SevenTenEleven Apple dev论坛:


命名空间不是每个文件;它们是每个目标(基于
产品模块名称构建设置)。所以你最终会得到像这样的

Namespaces are not per-file; they're per-target (based on the "Product Module Name" build setting). So you'd end up with something like this:

import FrameworkA
import FrameworkB

FrameworkA.foo()

所有Swift声明都被认为是$ b的一部分$ b一些模块,所以即使你说 NSLog (是的,它仍然存在)
你得到的Swift认为是 Foundation.NSLog

All Swift declarations are considered to be part of some module, so even when you say "NSLog" (yes, it still exists) you're getting what Swift thinks of as "Foundation.NSLog".

此外 Chris Lattner 关于命名空间的推文

Also Chris Lattner tweeted about namespacing.


命名空间隐含在Swift中,所有类(等)都隐含地由它们所在的模块(XCode目标)限定
。没有类前缀需要

Namespacing is implicit in Swift, all classes (etc) are implicitly scoped by the module (XCode target) they are in. no class prefixes needed

似乎与我一直在想的非常不同。

Seems to be very different what I have been thinking.

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

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