Objective-C 中如何命名常量?
Objective-C 中常量的命名约定是什么(或者最广泛使用的命名方式)?
extern
常量是否有不同的标准?
我见过的一些款式:
NSString* const kPreferenceFirstRun = @"FirstRun";
// Replace "XY" by a prefix representing your company, project or module
NSString* const XYPreferenceFirstRun = @"FirstRun";
What's the naming convention for constants in Objective-C (or most widely used way to name them)?
Is there a different criteria for extern
constants?
Some styles I have seen:
NSString* const kPreferenceFirstRun = @"FirstRun";
// Replace "XY" by a prefix representing your company, project or module
NSString* const XYPreferenceFirstRun = @"FirstRun";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一番谷歌搜索后,我发现了 Cocoa 官方编码指南。
总结一下:
extern
常量的标准相同我同意 itaiferber 的观点k 前缀样式更清晰,对于自动完成也更有用。了解这种风格是否比官方指南更受欢迎将会很有趣。
After a bit of googling I've found the official coding guidelines for Cocoa.
To sum up:
extern
constantsI agree with itaiferber that the k prefix style is clearer and also much more useful for autocompletion. It would be interesting to know if this style is more popular than the official guidelines.
在我看来,最佳实践是以大写字母命名常量。
但可可核心开发人员似乎不同意我的观点))他们使用 CamelCase 来表示常量
it's seems to me, the best practice is to name constants in upper-case.
but cocoa-core developers don't seem to share my opinion)) they use CamelCase for constants