Are namespace collisions really an issue in 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 中的一个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:命名空间冲突真的是 Objective-C 中的一个问题吗


基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01