Objective-C 没有命名空间,而且很多(例如 CocoaDevCentral 的 Cocoa 样式指南) 建议在你的类名前加上首字母以避免命名空间冲突.
Objective-C doesn't have namespaces, and many (such as CocoaDevCentral's Cocoa Style Guide) recommend prefixing your class names with initials to avoid namespace collision.
引用以上链接:
Objective-C 没有命名空间,所以在你的类名前加上缩写.这避免了命名空间碰撞",这是一种情况两段代码同名但做不同的事情.
Objective-C doesn't have namespaces, so prefix your class names with initials. This avoids "namespace collision," which is a situation where two pieces of code have the same name but do different things.
我想这是有道理的.但老实说,在相对较小的应用程序(比如 iPhone 游戏)的背景下,这真的是个问题吗?我真的应该将 MyViewController 重命名为 ZPViewController 吗?如果不是,那么命名空间冲突在什么时候真正成为一个问题?
That makes sense, I suppose. But honestly, in the context of a relatively small app (say, an iPhone game), is this really an issue? Should I really rename MyViewController to ZPViewController? If not, at what point do namespace collisions really become a concern?
如果您正在编写一个使用某些库集的应用程序,那么您已经知道您的命名空间是什么样的,您只需要选择不使用的名称即可与现有可用功能冲突.
If you're writing an application that uses some set of libraries, then you already know what your namespace looks like and you just need to select names that do not conflict with existing available functions.
但是,如果您正在编写一个 库 供他人使用,那么您应该选择一个合理唯一的前缀,以避免与其他库发生名称冲突.只有两个字符可能仍然会发生名称冲突,但频率会降低.
However, if you are writing a library for use by others, then you should pick a reasonably unique prefix to try to avoid name collisions with other libraries. With only two characters there may still be name collisions, but the frequency will be reduced.
这篇关于命名空间冲突真的是 Objective-C 中的一个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!