许多语言都支持文档注释,以允许生成器(如javadoc或doxygen)通过解析相同的代码来生成代码文档。
Swift有类似的文档注释功能吗?
许多语言都支持文档注释,以允许生成器(如javadoc或doxygen)通过解析相同的代码来生成代码文档。
Swift有类似的文档注释功能吗?
当前回答
是的。基本公共(我用Obj-C等效为它制作了片段)
objective - c:
/**
@brief <#Short description - what it is doing#>
@discussion <#Description#>
@param <#paramName#> <#Description#>.
@return <#dataType#> <#Description#>.
*/
斯威夫特
/**
<#Short inline description - what it is doing#>
<#Description#>
:param: <#paramName#> <#Description#>.
:returns: <#dataType#> <#Description#>.
*/
其他回答
是的。基本公共(我用Obj-C等效为它制作了片段)
objective - c:
/**
@brief <#Short description - what it is doing#>
@discussion <#Description#>
@param <#paramName#> <#Description#>.
@return <#dataType#> <#Description#>.
*/
斯威夫特
/**
<#Short inline description - what it is doing#>
<#Description#>
:param: <#paramName#> <#Description#>.
:returns: <#dataType#> <#Description#>.
*/
下面是一些在Xcode 6中用于记录swift代码的东西。它有很多bug,对冒号很敏感,但总比没有强:
class Foo {
/// This method does things.
/// Here are the steps you should follow to use this method
///
/// 1. Prepare your thing
/// 2. Tell all your friends about the thing.
/// 3. Call this method to do the thing.
///
/// Here are some bullet points to remember
///
/// * Do it right
/// * Do it now
/// * Don't run with scissors (unless it's tuesday)
///
/// :param: name The name of the thing you want to do
/// :returns: a message telling you we did the thing
func doThing(name : String) -> String {
return "Did the \(name) thing";
}
}
上述内容在快速帮助中呈现,正如您所期望的格式化数字列表、项目符号、参数和返回值文档一样。
所有这些都没有被记录下来-档案雷达来帮助他们前进。
Jazzy可以帮助生成漂亮的苹果风格的文档。 下面是一个示例应用程序,详细介绍了如何快速使用和配置。
https://github.com/SumitKr88/SwiftDocumentationUsingJazzy
从Xcode 5.0开始,支持Doxygen和HeaderDoc结构化注释。
源
在Xcode编辑器->结构->添加文档。