xcode Objective C 方法注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7493931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:59:37  来源:igfitidea点击:

Objective C Method Comments

iphoneobjective-cxcodeipadcomments

提问by Jonathan

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

为 Objective C 注释方法的正确方法是什么?例如,在 .Net 中,我会添加一个 xml 注释,如:

/// <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?

目标 C 是否有等价物?

回答by bryanmac

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.

不要忘记用于阻塞代码的 pragma 标记。它帮助 XCode 隔离下拉列表中的方法。它还在视觉上分解了您的源文件,使其更易于阅读。

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:

它最终在 XCode 中执行此操作:

enter image description here

在此处输入图片说明

回答by zaph

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

有可以使用的 appledoc 标题文档,与 Apple 使用的相同。

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.

对于单个方法,最好的指导是使用非常具有描述性的名称,这在 Objective-C 中相当容易,参数散布在方法名称中。这通常不需要单独的参数注释。

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

正如在任何语言中一样,描述性方法名称和简短的单一用途方法胜过冗长的注释,这些注释随着代码的变化而老化。

回答by Jorge Israel Pe?a

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.

因此,对objective-c 的等效评论风格将取决于您选择的文档生成器。据我所知,没有默认的。

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

如果您想要提供类似于 Apple 自己的开发人员文档的结果,您可以使用Doxygenappledoc 之类的东西。此页面详细介绍了评论格式。示例:GBComment.h

回答by Lithu T.V

How I do is like this,

我的做法是这样的

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

回答by allan

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

this is displayed on quick help

这显示在快速帮助上

thinks

认为

回答by user891123

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;*/