問題描述
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模板網!