objectAtIndex: or objectForKey: instead of subscripting
ID |
objectivec.maintainability.use_object_subscripting |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Idiom |
Language |
Objective-C |
Description
Prefer subscripting - items[0], map[@"key"] - over objectAtIndex: and objectForKey:. It reads more directly and is the modern Objective-C form.
Rationale
Prefer subscripting - items[0], map[@"key"] - over objectAtIndex: and objectForKey:. It reads more directly and is the modern Objective-C form.
The following code illustrates the pattern detected by this rule:
@implementation Accessors
- (void)lookups:(NSArray *)items dict:(NSDictionary *)map {
// FLAGGED: objectAtIndex: or objectForKey: instead of subscripting
id first = [items objectAtIndex:0];
// FLAGGED: objectAtIndex: or objectForKey: instead of subscripting
id value = [map objectForKey:@"key"];
id modern = items[0];
NSLog(@"%@ %@ %@", first, value, modern);
}
@end