方法'文档'

时间:2009-07-07 17:26:24

标签: objective-c

记录方法用法的objective-c语法是什么?这是在.h或.m文件中完成的吗?

在C#中,使用类似的东西:

/// <summary>
/// Executes an HTTP GET command and retrieves the information.     
/// </summary>
/// <param name="url">The URL to perform the GET operation</param>
/// <param name="userName">The username to use with the request</param>
/// <param name="password">The password to use with the request</param>
/// <returns>The response of the request, or null if we got 404 or nothing.</returns>
protected string ExecuteGetCommand(string url, string userName, string password) {
...
}

这是用#pragma指令完成的吗?

谢谢,

Craig Buchanan

2 个答案:

答案 0 :(得分:20)

Xcode 5中有一项新功能可以记录您的方法。在头文件中,您可以向函数添加注释,以便将它们显示在文档中:

/*! Executes an HTTP GET command and retrieves the information.
 * \param url The URL to perform the GET operation
 * \param userName The username to use with the request
 * \param password The password to use with the request
 * \returns The response of the request, or null if we got 404 or nothing
 */
- (NSString *)executeGetCommandWithURL:(NSURL *)url userName:(NSString *)aUserName andPassword:(NSString *)aPassword;

注意第一行的感叹号。

此文档将显示在Xcode右侧窗格的“快速帮助”中,当您键入时,说明将显示在功能自动完成中。

答案 1 :(得分:4)

Objective-C没有内置的文档功能。 Apple包含一个名为Headerdoc的工具,可以从源文件生成文档,但有several better options。我认为最流行的是Doxygen,在这种情况下,语法是Java风格的/** Documentation here */。您可以查看Wikipedia page的示例,了解它的使用方法(尽管使用其他语言)。 Apple的网站上有instructions for using Doxygen with Xcode