Named parameters in Objective-C

Objective-C has a mechanism that lets you name the parameters that a method accepts. It has taken me a while to really start using this capability to it’s potential, but I think that today I finally have. Check out this method definition.

- (void) assert: (PlayArea *) area has: (NSString *) value atX: (int) x Y: (int) y {

This lets me write the following method call.

[self assert: area has: @"W" atX: 0 Y: 1];

I really like writing lines of code that tell you exactly what they are doing. Don’t you?


Leave a Reply