objective-c - 如何在 Objective-C 中命名常量?

Objective-C 中常量的命名约定是什么(或最广泛使用的命名方式)?

extern 常量有不同的标准吗?

我见过的一些款式:

NSString* const kPreferenceFirstRun = @"FirstRun";

// Replace "XY" by a prefix representing your company, project or module
NSString* const XYPreferenceFirstRun = @"FirstRun"; 

最佳答案

经过一番谷歌搜索后,我找到了 official coding guidelines for Cocoa .

总结一下:

  • 以两个或三个字母开头 prefix全大写
  • 在 UpperCamelCase 中休息
  • extern 常量的相同标准

我同意 itaiferber 的观点,即 k 前缀样式更清晰,对自动完成也更有用。想知道这种风格是否比官方指南更受欢迎。

https://stackoverflow.com/questions/4058235/

相关文章:

ios - 在从 UIViewController 调用的非保留完成中引用 self 时,weakS

objective-c - 调用 -retainCount 被认为是有害的

ios - scaledValueForValue : called on a font that

iphone - 关于带有文本字段的 UIAlertView...

c++ - UInt8 和 uint8_t 有什么区别

ios - Objective-C,如何获取 UTC 时区的当前日期?

iphone - MKMapView 缩放到 viewDidLoad 上的用户位置?

objective-c - CAEmitterLayer 在触摸事件中随机发射不需要的粒子

iphone - viewWillAppear,viewDidAppear 没有被调用,没有触发

objective-c - NSBundle pathForResource 为 NULL