You can get the maximum value in an NSSet full of NSNumbers using Key-Value-Coding like so:
NSSet *set = [NSSet setWithArray:@[ @1,@2,@3,@4,@5 ]]; NSNumber *maxValue = [set valueForKeyPath:@"@max.self"];
maxValue is now
It took me ages to find the correct KVC syntax for this. Source is linked below, and has a bunch of other cool uses of KVC.
Key-value coding is one of my more favorite things about Cocoa (up there with
NSPredicate). Basically, it allows you to access properties of objects by name (ie, as a string) rather than invoking a method (er… sending a message)…