Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which method name fits in best with Objective-C/Cocoa conventions?

Here's a quicky question. Which method name makes the most sense for an Objective-C Cocoa application?

-(void) doSomethingWithAnimation:(BOOL)animated

or:

-(void) doSomething:(BOOL)animated

or even:

-(void) doSomethingAnimated:(BOOL)animated
like image 571
Mike Akers Avatar asked Dec 30 '22 08:12

Mike Akers


2 Answers

I think the Cocoa convention would give your examples the following semmantics (ignoring the BOOL type for the argument, obviously):

-(void) doSomethingWithAnimation:(BOOL)animated

would actually expect an Animation as the parameter (i.e. something that represents the animation.

-(void) doSomething:(BOOL)animated

would expect the Something to do.

-(void) doSomethingAnimated:(BOOL)animated

would, as Noah answered, do something with optional animation.

like image 119
Barry Wark Avatar answered Feb 14 '23 01:02

Barry Wark


-(void)doSomethingAnimated:(BOOL)animated seems most consistent with Apple's naming style. For reference, check the iPhone UIKit docs - UINavigationController's -popToRootViewControllerAnimated: method, for instance.

like image 30
Noah Witherspoon Avatar answered Feb 14 '23 01:02

Noah Witherspoon