本文介绍了在Objective-C中,名称空间冲突真的是一个问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

从以上链接引用:

我想这是有道理的.但老实说,在相对较小的应用程序(例如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中,名称空间冲突真的是一个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 02:17