Cocoa: +keyPathsForValuesAffecting<Key> lowercase letter mistake.

When you use KVO and create your class method with a name matching the pattern +keyPathsForValuesAffecting<Key> don't forget to capitalize the first letter of the "Key" part.

It might seem obvious to me now, especially with that uppercase "K" in "Key", but all my keys start with a lowercase letter, not uppercase (in keeping with Apple style guidelines), and the KVO Protocol Reference documentation does not call out the uppercase letter requirement. This particular warning is buried within the KVO Programming Guide, instead.

+ (NSSet *)keyPathsForValuesAffectingAmountInOtherCurrency {
 return [NSSet setWithObjects: @"dollarsToConvert", @"exchangeRate", nil];

+ (NSSet *)keyPathsForValuesAffectingamountInOtherCurrency {
 return [NSSet setWithObjects: @"dollarsToConvert", @"exchangeRate", nil];

Yes, the bad version even looks bad, so I guess I should have figured that out faster.

No comments:

Post a Comment