Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming conventions on IBAction functions

Tags:

I am doing another iOS application and I wonder if there are any naming conventions or good practices on how to name actions that I could follow. I am thinking of names on the functions that are invoked when user e.g. touches a button.

like image 419
LuckyLuke Avatar asked Aug 28 '11 15:08

LuckyLuke


People also ask

What naming convention should be used for method names?

Interface names should be capitalized like class names. Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter.

What is naming convention and example?

Naming-convention definitionA collection of rules followed by a set of names which allow users to deduce useful information, based on the names' character sequence and knowledge of the rules followed; such as Manhattan's East-West streets being called "Streets" and its North-South streets being called "Avenues". noun.

What is naming convention in programming?

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation.

What naming convention is used for most variables?

For variables, the Java naming convention is to always start with a lowercase letter and then capitalize the first letter of every subsequent word. Variables in Java are not allowed to contain white space, so variables made from compound words are to be written with a lower camel case syntax.


2 Answers

Go with Apple's guidelines. What were in the past good suggestions have now been codified in ARC (Automatic Reference Counting) and are necessary to be followed for ARC to generate correct code. Using these guidelines may well future-proof your code, it did for ARC!

Apple's guidelines Coding Guidelines for Cocoa

From the method naming section:

Start the name with a lowercase letter and capitalize the first letter of embedded words. Don’t use prefixes.

There are two specific exceptions to these guidelines. You may begin a method name with a well-known acronym in uppercase (such as TIFF or PDF)), and you may use prefixes to group and identify private methods

For methods that represent actions an object takes, start the name with a verb.

- (void)invokeWithTarget:(id)target; - (void)selectTabViewItem:(NSTabViewItem *)tabViewItem 

Do not use “do” or “does” as part of the name because these auxiliary verbs rarely add meaning. Also, never use adverbs or adjectives before the verb.

If the method returns an attribute of the receiver, name the method after the attribute. The use of “get” is unnecessary, unless one or more values are returned indirectly.

- (NSSize)cellSize; 

Use keywords before all arguments.

- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag 

Make the word before the argument describe the argument.

- (id)viewWithTag:(int)aTag; 
like image 72
zaph Avatar answered Oct 09 '22 21:10

zaph


I haven't come across much in the way of specifics when it comes to naming conventions for IBActions. However, if you were to follow the trend Apple seems to be setting in its sample apps, then some examples are as follows:

-(IBAction)cameraAction:(id)sender; -(IBAction)done:(id)sender; -(IBAction)takePhoto:(id)sender; 

Hope this helps.

like image 30
Andrew Little Avatar answered Oct 09 '22 20:10

Andrew Little