开发者

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>
/开发者_StackOverflow// <param name="FileName">The document's original filename.</param>  
/// <returns>Decoded filename</returns>  

Is there an equivalent for Objective-C?


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:

Objective-C Method Comments


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.


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


How I do is like this,

//-----------------------------------------------------------------------------------------------------//
#pragma mark - Table view Datasource -
//-----------------------------------------------------------------------------------------------------//


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

this is displayed on quick help

thinks


You would use

//for a single line comment
/*Use this for the start of a block comment
*/Use this for the end of a comment
   /*text text text;
   code code;
   code code code;//comment
   code;//comment
   code;*/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜