Objective-C类前缀 [英] Objective-C Class Prefixes

查看:132
本文介绍了Objective-C类前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您喜欢使用ObjC类命名吗?我有点不确定什么是最合理的方法,所以这将是很高兴听到一些其他意见。



苹果建议前缀可可类,因为ObjC doesn不支持命名空间。除非你扩展(类别,类扩展等)一个NSClass,否则Google ObjC风格指南(我最主要的目标)会抛弃它们。



不要前缀类,因为我也认为这是一个浪费的字母,并不有助于一个原因。它应该只在框架代码中使用,表示这个类属于它,而不是你的应用程序的类,但我不会在应用程序级别使用它。





我的结论(请随意






应用程式等级类别:




  • 我决定使用1个字母前缀(如CMyClass)。主要原因是文件组织的目的(例如在Finder中更好的分组),它仍然使用比前缀长度2或更多的类名字母。


    • 对可可类使用前缀 C (例如 CAudioController.h

    • 对实用程序集合使用前缀 U (plain C,例如 USystemAudio.h
    • p>


      • 使用2个或更多自定义字母,优先选择唯一的前缀类,因为它可能会与其他应用共享。



      类别




      • 类别命名如下: NSClassName + ExtensionPurpose


      解决方案

      我的一般方法是前缀作为框架或可加载bundle的一部分的类名称,即可能在几个应用程序和其他框架之间共享的类,但不会对显示为独立应用程序的一部分的类感到烦恼。



      如果史蒂夫·乔布斯给我一个愿望,那就是在Objective-C 3.0中有名字空间(明天可用)。


      What's your preference with naming ObjC classes? I'm a little uncertain what would be the most reasonable approach on this so it would be nice to hear some other opinions.

      Apple recommends prefixing cocoa classes, because ObjC doesn't support namespaces. The Google ObjC styleguide (which i mostly aim for) does away with them, unless you're extending (category, class extension etc.) a NSClass.

      My preference would be NOT to prefix classes, because i also think it's a waste of letters and doesn't contribute to a cause. It should only be used in framework code to signal that this class belongs to it and not to your app's classes, but i wouldn't use it on application level.

      What's yours, and most importantly WHY?


      My Conclusion (please feel free to add your comments to produce the most informed decision)


      Application Level Classes:

      • I decided to go with 1 Letter Prefixes (like CMyClass). The main reasons are for file organization purposes (e.g. better grouping in Finder), and it still uses less class name letters than prefixes with length 2 or more.
        • Use the prefix 'C' for cocoa classes (e.g. CAudioController.h)
        • Use the prefix 'U' for utility collections (plain C, e.g. USystemAudio.h)

      Framework Level Classes:

      • Prefix classes with 2 or more custom letters, preferrably unique, since it will probably be shared with other apps.

      Categories

      • Categories are named as follows: NSClassName+ExtensionPurpose

      解决方案

      My general approach is to prefix class names that are part of a framework or loadable bundle i.e. classes that might be shared amongst several applications and with other frameworks, but not to bother with classes that appear as part of a standalone application.

      If Steve Jobs granted me one wish it would be to have name spaces in Objective-C 3.0 (which would be available tomorrow).

      这篇关于Objective-C类前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆