【问题标题】:Inline Documentation Comments for Objective-C Protocols and their Methods & PropertiesObjective-C 协议及其方法和属性的内联文档注释
【发布时间】:2014-03-18 16:58:44
【问题描述】:

问题:
应该为示例 SCParserDelegate 协议中的每个方法编写文档注释。


上下文:
我正在构建一个供第 3 方开发人员使用的解析框架。 (这是我的第一个框架项目,所以我的开发过程是高度学术性的,以最大限度地学习。)


示例代码:

/** @protocol SCParserDelegate
 *   @brief Protocol for a Delegate to handle Callbacks when an SCParser finds Tags
 */
@protocol SCParserDelegate
@required
@property (readonly) BOOL processing;
@optional
-(void)parserDidStart:(SCParser *)parser;
-(void)parserDidFinish:(SCParser *)parser;
-(void)parser:(SCParser *)parser didOpenTag:(SCTag *)tag;
-(void)parser:(SCParser *)parser didCloseTag:(SCTag *)tag;
-(void)parser:(SCParser *)parser didSingleTag:(SCTag *)tag;
-(void)parser:(SCParser *)parser whitelistDeniedTag:(SCTag *)tag;
-(void)parser:(SCParser *)parser parseErrorOccurred:(NSError *)parseError;
-(void)parser:(SCParser *)parser foundCharacters:(NSString *)content;
@end


问题:
如何在上面的示例代码中为每个方法和属性手动编写自己的文档注释块?

【问题讨论】:

    标签: objective-c documentation comments protocols code-documentation


    【解决方案1】:

    听起来您想使用VVDocumenter 之类的东西。

    来自他们的 Github 页面:

    编写文档对于开发来说非常重要,但它真的很重要 Xcode 很痛苦。想想你浪费了多少时间 按“*”或“/”,然后一次又一次地键入参数。现在, 您可以找到要记录的方法(或任何代码),并且 输入///,将为您和所有参数生成文档和 return 会被提取成 Javadoc 风格,兼容 与 appledoc、Doxygen 和 HeaderDoc。你可以只填写内联 占位符标记来完成您的文档。

    【讨论】:

    • 谢谢,很高兴知道内联文档有自动解决方案。但是我的问题是学术性质的,所以我实际上是在特别要求了解有关内联代码文档注释块以及如何正确使用它们的更多信息
    • 跟进;我安装了 VVDocumenter,它运行良好。这对我来说绝对是一个优秀的插件。 :)
    【解决方案2】:

    NSHipster 在这方面有很好的 cmets。 http://nshipster.com/documentation/

    至于委托,最好通知符合协议的人何时发送消息,例如:

    /*!
     * @field processing   Flag indicating that the operation is currently in process
     */
    @property (readonly) BOOL processing;
    
    /*!
     * Sent right after the parser began
     * 
     * @param parser (Something about the parser)
     */
    -(void)parserDidStart:(SCParser *)parser;
    
    /*!
     * Sent after the parser opens the given tag (maybe some hints as to what the delegate may do)
     *
     * @param parser (Words about the parser)
     * @param tag    (Something about the tag)
     */
    -(void)parser:(SCParser *)parser didOpenTag:(SCTag *)tag;
    

    还有其他有用的标签,例如@return 和@warning。 VVDocumenter 非常有用,所以我建议安装它。

    【讨论】:

    • 这些例子对我来说绝对应该有用。有可能我检查错了。在 Xcode 中,我通过在 Intellisense 简报中检查文档注释来测试它。有没有更好的地方我可以检查以确保文档注释在 Xcode 中正常工作?
    • 尝试按住选项键,将鼠标悬停在方法或属性上,然后单击。如果可用,您应该会看到一个带有文档注释的对话框。这也适用于苹果的方法。
    • 做到了!非常感谢!
    • headerdoc 文档不适用于 xcode 7.2 和 swift。你们知道发生了什么吗?
    猜你喜欢
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    相关资源
    最近更新 更多