Works as intended.
…Objects:
and forKeys:
should be aligned as they form part of the same method signature.
It might be easier to format your code if you use the new object literal syntax:
- (int)minBrokenPieces {
NSDictionary *mapping = [NSDictionary dictionaryWithObjects:@[@"3", @"4", @"4", @"5", @"6", @"7", @"8"]
forKeys:[Note types]];
[(NSString *)mapping[self.note.type] integerValue];
}
As for the code itself, it seems a bit dangerous to define these constants in one place and the note types elsewhere. Also, why use strings, when NSNumbers would suffice?
(This code assumes this function is only called from one thread).
- (int)minBrokenPieces {
static NSDictionary *mappings;
if (!mappings) {
mappings = @{
noteType1 : @3,
noteType2 : @4,
noteType3 : @4,
noteType4 : @5,
noteType5 : @6,
noteType6 : @7,
noteType7 : @8,
};
}
NSAssert(mappings[self.note.type] != nil, @"Used a note type for which there is no minBrokenPieces defined");
return [mappings[self.note.type] intValue];
}