Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C Method Comments

What is the proper way to comment methods for Objective-C? For example, in .Net I would add a xml comment like:

/// <summary>
/// Summary of method
/// </summary>
/// <param name="FileName">The document's original filename.</param>  
/// <returns>Decoded filename</returns>  

Is there an equivalent for Objective-C?

like image 808
Jonathan Avatar asked Sep 21 '11 02:09

Jonathan


5 Answers

Don't forget about pragma marks for blocking your code. It helps XCode segregate the methods in the dropdown. It also visually breaks up your source file and makes it easier to read.

Here's how I block sections of code:

///////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark View Lifecycle
#pragma mark -
///////////////////////////////////////////////////////////////////////////

- (void) functionsHere

It ends up doing this in XCode:

enter image description here

like image 116
bryanmac Avatar answered Sep 25 '22 00:09

bryanmac


There are appledoc header docs that can be used, the same ones Apple uses.

For individual methods the best guide is to use very descriptive names, this is rather easy in Objective-C with the parameters interspersed in the method name. This generally obviates the need for individual parameter comments.

As in any language descriptive method names and short single purpose methods beats lengthily comments that age poorly as code changes.

like image 42
zaph Avatar answered Sep 25 '22 00:09

zaph


The style of commenting you mention seems to be the kind that a documentation generator picks up to generate documentation for you.

The equivalent style of commenting on objective-c would therefore be dependent on the documentation generator you choose. There is no default one as far as I know.

You can use something like Doxygen, or appledoc if you want something that gives results similar to Apple's own developer documentation. This page details the commenting format. Example: GBComment.h

like image 44
Jorge Israel Peña Avatar answered Sep 24 '22 00:09

Jorge Israel Peña


How I do is like this,

//-----------------------------------------------------------------------------------------------------//
#pragma mark - Table view Datasource -
//-----------------------------------------------------------------------------------------------------//
like image 27
Lithu T.V Avatar answered Sep 27 '22 00:09

Lithu T.V


/**
*   @brief  set refresh datetime
*
*   @param  value of refresh datetime
*
*   @return
*
*/

this is displayed on quick help

thinks

like image 44
allan Avatar answered Sep 24 '22 00:09

allan