Cocoa类别命名约定的最佳做法 [英] Best practice for Cocoa category naming conventions

查看:142
本文介绍了Cocoa类别命名约定的最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在整理我的古代Cocoa代码以使用现代命名约定。有很多关于最佳实践的讨论,但我不确定一件事。



我想在类别方法名称中添加前缀,以确保唯一性。



我的问题是: NSDictionary

/ code>类别方法像 -copyDeep 执行深拷贝?该方法用于命名为 -deepCopy ,但我反转了这个词,因为分析器查找copy的前缀。因此,我估计不能添加一个前缀。并且在方法名称的中间或末尾有前缀似乎混乱和不一致。



我也会对前缀的风格感兴趣 - 我目前使用 DS (对于Dejal系统)类前缀。但我知道,苹果现在想保留所有两个字符前缀为自己,所以我考虑使用 Dejal ,例如。我的类 DSManagedObject 将被重命名为 DejalManagedObject 。并返回类别,他们的方法将被重命名添加一个 dejal 前缀,例如。从 -substringFromString: -dejalSubstringFromString:。但 -dejalCopyDeep 会混淆分析仪,所以也许我不得不对这种方法不一致,并使用 -copyDeepDejal -copyDeep_dejal



我将重新发布我的类别和各种类作为开源,

解决方案

我通过电子邮件向Apple Application Frameworks Evangelist发送了电子邮件,得到了一条建议为类别方法名称加上前缀的回复。这与上述WWDC10会议中的建议冲突,但我认为反映了苹果目前的想法。



他建议只看看beta种子API差异以发现冲突,这是我一直在做的。


I am tidying up my ancient Cocoa code to use modern naming conventions. There has been lots of discussion on best practices, but I'm unsure of one thing.

I'm thinking about adding a prefix to category method names, to ensure uniqueness. It seem generally agreed that this is a good idea, though most people probably don't bother.

My question is: what about a NSDictionary category method like -copyDeep that does a deep copy? The method used to be named -deepCopy, but I reversed the words as the analyzer looks for a prefix of "copy". Therefore I presumably couldn't add a prefix. And having the "prefix" in the middle or end of the method name seems messy and inconsistent.

I'd also be interested in thoughts on the style of prefix -- I currently use DS (for Dejal Systems) for class prefixes. But I know that Apple now wants to reserve all two-character prefixes for themselves, so am thinking about using Dejal, e.g. my class DSManagedObject would be renamed as DejalManagedObject. And getting back to categories, their methods would be renamed to add a dejal prefix, e.g. from -substringFromString: to -dejalSubstringFromString:. But -dejalCopyDeep would confuse the analyzer, so maybe I'd have to be inconsistent for such methods, and use -copyDeepDejal or -copyDeep_dejal?

I will be re-releasing my categories and various classes as open source once I've cleaned them up, so following the latest conventions will be beneficial.

解决方案

I emailed the Apple Application Frameworks Evangelist about this, and got a reply that recommended not prefixing category method names. Which conflicts with the advice in the aforelinked WWDC10 session, but I assume reflects Apple's current thinking.

He recommended just looking at the beta seed API diffs to spot conflicts, which is what I've always been doing.

这篇关于Cocoa类别命名约定的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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