命名空间冲突真的是 Objective-C 中的一个问题吗

Are namespace collisions really an issue in Objective-C?(命名空间冲突真的是 Objective-C 中的一个问题吗?)
本文介绍了命名空间冲突真的是 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.

引用以上链接:

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 中的一个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)
HTTPS request using volley(使用 volley 的 HTTPS 请求)