5 ms·
Objective-C Parameter Names Unneeded in Headers
In an Objective-C "@interface" the names for parameter variables don't really matter. In fact, they can all be exactly the same name, and different from the "@implementation", which is useful in header files.
Method names are almost always descriptive enough. If parameter names are identical, there's less to maintain; I like using a single underscore "_" for all header-file parameters.
Here's an example of a method that has lots of parameters, where the parameter names are kind of pointless:
@interface UIView : . . .
+ (void)
transitionWithView:(UIView *) view
duration:(NSTimeInterval) duration
options:(UIViewAnimationOptions) options
animations:(void (^)(void)) animations
completion:(void (^)(BOOL finished)) completion;
They could actually have just said this (changing all names to "_"):
@interface UIView : . . .
+ (void)
transitionWithView:(UIView *)_
duration:(NSTimeInterval)_
options:(UIViewAnimationOptions)_
animations:(void (^)(void))_
completion:(void (^)(BOOL finished))_;
- kstenerud 15y agoIf you want to generate documentation for your API, this won't work. Documentation generators such as doxygen require unique parameter names in order to function correctly. Slightly related, I'd argue that "animations" is very poorly chosen. A plural noun indicates a set or collection of objects, whereas this is a block pointer to be used for... something...
- makecheck 15y agoIt's possible to make Doxygen look at a source file instead of a header...at least in C++ it is. As for the name, this is Apple's method name from UIView so ask them. :)
- kstenerud 15y agoIt might be possible with Objective-C as well, but then you end up with it exposing all your private stuff (unless you manually mark everything internal as "hands off"). Not sure which would end up being more work. Furthermore, it means that the users of your API can't look at the header file (via CMD-click) for an explanation.