On Aug 1, 2012, at 6:00 AM, Erik Stainsby <erik.stain...@roaringsky.ca> wrote:
> What I have come up with is this: > > [sortkeys sortUsingComparator:^NSComparisonResult(id obj1, id obj2) { > return [(NSString*)obj1 compare:(NSString*)obj2 ]; > } ]; > > Is this a sane approach ? Seems a bit fussy to have to spec the cast like > this. Or is this just the what-is of this kind of functionality? The "(NSString*)" casts are unnecessary, as "id" is type-compatible with any object-pointer type. You can also remove the "NSComparisonResult", as the compiler can infer the return type from the 'return' statement. Alternatively you can change the parameter types to NSString*, which makes the block more type-safe: [sortkeys sortUsingComparator:^(NSString* obj1, NSString* obj2) { return [obj1 compare:obj2 ]; } ]; Or since your block just calls one method, you could just use: [sortKeys sortUsingSelector: @selector(compare:)]; —Jens _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com