且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Swift中使用命名空间?

更新时间:2023-11-13 23:47:16

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.