Variable name is not lowerCamelCase

ID

objectivec.maintainability.naming_identifier_style

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Naming

Language

Objective-C

Description

Reports the declaration of a variable whose name is not lowerCamelCase - it starts with an uppercase letter (AccountLabel), or it separates words with underscores (user_count, TOTAL_POSTED). A single leading underscore is allowed, because that is the Cocoa convention for an instance variable, and a name containing a double underscore is left to the reserved-identifier rule so that one declaration is not reported twice. Only standalone declarations are reported; method parameters are not.

Rationale

Cocoa gives each kind of name a distinct shape - UpperCamelCase for classes and protocols, lowerCamelCase for variables, methods and properties, k-prefixed camel case for constants, and ALL_CAPS for preprocessor macros - so a reader can tell what a name refers to before looking it up. A variable spelled TOTAL_POSTED reads as a macro, which changes how a reader expects it to behave: macros have no scope, no type, and are not addressable. Mixing the conventions removes information the reader was relying on.

The following code illustrates the pattern detected by this rule:

@implementation Ledger {
}

- (void)post {
    // FLAGGED: Variable name is not lowerCamelCase
    NSInteger user_count = 0;

    NSLog(@"%ld %@ %ld %@ %ld %@ %@ %ld %ld", (long)user_count, AccountLabel,
          (long)TOTAL_POSTED, _posted_label, (long)userCount, accountLabel, _cachedLabel,
          (long)count, (long)_pendingCount);
}
@end

Remediation

Rename the variable to lowerCamelCase: user_count becomes userCount, AccountLabel becomes accountLabel. For a value that really is a constant, use the Cocoa constant convention instead of ALL_CAPS - static const NSInteger kTotalPosted = 0;.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved