The Apple style guides for naming methods say both "Don’t use “and” to link keywords that are attributes of the receiver." and "If the method describes two separate actions, use “and” to link them." In many cases, neither of these conditions apply. For example, let's say I have a function to do some work and call a selector on a target when it is done. Should this be named
- (void)findObjectsInBackgroundWithTarget:(id)target andSelector:(SEL)selector;
or should this be named
- (void)findObjectsInBackgroundWithTarget:(id)target selector:(SEL)selector;
In that example, the selector and target are related, but not through being attributes of the receiver. A similar example is to retrieve an object with particular attributes, but the object is not the receiver of the method. Should this function be
+ (Thing *)getThingWithName:(NSString *)name andId:(NSString *)thingId;
or should this be named
+ (Thing *)getThingWithName:(NSString *)name id:(NSString *)thingId;
I know this might seem like a minor thing, but it's nice to use the style everyone expects.
According to what Apple says, you should use "and" only if the name of your method describes the action the method does, i.e. -(void)doThisAndThat
, so in both of your examples you should not use "and" in methods' names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With