I am having a problem with method naming. I want to follow the method naming format as seen in UITableViewDataSource:
- (int)numberOfSectionsInTableView:(UITableView *)tableView;
but my class name is much longer than ‘UITableView’ — it’s XYPagedContentScrollView where XY is the class prefix for the project. I have a delegate protocol:
@protocol XYPagedContentScrollViewDelegate <NSObject>
- (CGFloat)defaultPageHeightForPagedContentScrollView:(XYPagedContentScrollView *)pagedContentScrollView;
@end
and this method name looks ridiculously long. I know it is not a strict rule, but I just wonder is there any way to deal with the long name and still conform to Apple’s naming convention? Something like:
@protocol XYPagedContentScrollViewDelegate <NSObject>
- (CGFloat)defaultPageHeightForPagedContentScrollView:(XYPagedContentScrollView *)pagedContentSV;
@end
or even:
@protocol XYPagedContentScrollViewDelegate <NSObject>
- (CGFloat)defaultPageHeightForPCScrollView:(XYPagedContentScrollView *)pagedContentSV;
@end
Can anyone help?
The length of a method is not limited by the language in any way, so feel free to make it as long as you want.
It may look bad at first, but the more verbose it is, the less chance you have of conflicts later down the line.
My rule is, if it looks like it could conflict with another method (especially if it’s a delegate method), it needs a longer name.
Now, with that said, don’t make names ridiculously long,so that they are 100s of characters in length, like this:
Instead, consider wrapping it in a dictionary of the event details:
This simplifies the method signature, and allows the receiver to only pull out the variables they need.