Property name is not lowerCamelCase
ID |
objectivec.maintainability.property_declaration |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming |
Language |
Objective-C |
Description
Reports a property whose name breaks Cocoa naming - it starts with a single capital letter (Balance), starts with an underscore, separates words with underscores (account_label, TOTAL_POSTED), or prefixes the getter with get. A name that opens with an uppercase acronym, as in URL or URLString, is the Cocoa form and is not reported. A declaration carrying a trailing attribute macro after the name is not matched.
Rationale
A property name is not only a name: it is the getter selector, the setName: selector, and the key that key-value coding and key-value observing look the value up by. Cocoa gives each kind of name its own shape, so TOTAL_POSTED reads as a preprocessor macro and Balance reads as a class, and a reader has to look the declaration up to find out which it is. The get prefix is worse than cosmetic - in Cocoa a get-prefixed method returns its value through an out-parameter, so getDisplayName promises an interface the property does not have. A leading underscore collides with the naming Apple reserves for the synthesised backing ivar.
The following code illustrates the pattern detected by this rule:
@interface Account : NSObject
// FLAGGED: Property name is not lowerCamelCase
@property (nonatomic, copy) NSString *AccountLabel;
@end
@implementation Account
@end
Remediation
Rename the property to lowerCamelCase - account_label becomes accountLabel, Balance becomes balance - and drop a get prefix, since the property already is the getter. Where the getter needs a different name, use the attribute instead of the prefix, as in @property (nonatomic, assign, getter=isSettled) BOOL settled;.