Here are some recommended coding guidelines from Apple for Cocoa.

Here are some I have written down to help me remember.

Good Coding conventions


== Naming methods

For methods representing actions objects take start with a verb
– (void)invokeWithTarget:(id)target;
– (void)selectTabViewItem:(NSTabViewItem *)tabViewItem

If a method returns an attribute name the method after the attribute. No gets.
– (NSSize)cellSize;

Use keywords before all arguments
– (void)sendAction:(SEL)aSelector toObject:(id)anObject forAllCells:(BOOL)flag; — good
– (void)sendAction:(SEL)aSelector :(id)anObject :(BOOL)flag; — bad

Make the word before the argument describe the argument
– (id)viewWithTag:(NSInteger)aTag; – good
– (id)taggedView:(int)aTag; — bad

Add new keywords to the end of existing methods when you create a method more specific
– (id)initWithFrame:(CGRect)frameRect;
– (id)initWithFrame:(NSRect)frameRect mode:(int)aMode cellClass:(Class)factoryId numberOfRows:(int)rowsHigh numberOfColumns:(int)colsWide;

And don’t use and to link keywords
– (int)runModalForDirectory:(NSString *)path file:(NSString *) name types:(NSArray *)fileTypes; — right
– (int)runModalForDirectory:(NSString *)path andFile:(NSString *)name andTypes:(NSArray *)fileTypes; — wrong

Note: link words are OK for the first argument. See above.

If the method describe two separate actions, can use and to link them
– (BOOL)openFile:(NSString *)fullPath withApplication:(NSString *)appName andDeactivate:(BOOL)flag;

== Accessor Methods

Access methods are those that set and return the value of a property of an object.

– (type)noun;
– (void)setNoun:(type)aNoun;

– (NSString *)title;
– (void)setTitle:(NSString *)aTitle;

– (BOOL)isAdjective;
– (void)setAdjective:(BOOL)flag;

– (BOOL)isEditable;
– (void)setEditable:(BOOL)flag;

– (BOOL)verbObject;
– (void)setVerbObject:(BOOL)flag;

– (BOOL)showsAlpha;
– (void)setShowsAlpha:(BOOL)flag;

Verb should be in simple present tense.

Don’t twist a verb into an adjective by using a participle:
– (void)setAcceptsGlyphInfo:(BOOL)flag; — Right.
– (BOOL)acceptsGlyphInfo; — Right.
– (void)setGlyphInfoAccepted:(BOOL)flag; — Wrong.
– (BOOL)glyphInfoAccepted; — Wrong

You may use modal verbs (verbs preceded by “can”, “should”, “will”, and so on) to clarify meaning, but don’t use “do” or “does”.

– (void)setCanHide:(BOOL)flag; — Right.
– (BOOL)canHide; — Right.
– (void)setShouldCloseDocument:(BOOL)flag; — Right.
– (BOOL)shouldCloseDocument; — Right.
– (void)setDoesAcceptGlyphInfo:(BOOL)flag; — Wrong.
– (BOOL)doesAcceptGlyphInfo; — Wrong.

== Delegate Methods

Start the name by identifying the class of the object that’s sending the message
– (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(int)row;
– (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename;

Use ‘did’ or ‘will’ for methods that are invoked to notify the delegate that something has happened or is about to happen.
– (void)browserDidScroll:(NSBrowser *)sender;
– (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window;