许多语言都支持文档注释,以允许生成器(如javadoc或doxygen)通过解析相同的代码来生成代码文档。
Swift有类似的文档注释功能吗?
许多语言都支持文档注释,以允许生成器(如javadoc或doxygen)通过解析相同的代码来生成代码文档。
Swift有类似的文档注释功能吗?
当前回答
我在Xcode二进制文件中发现了一些有趣的东西。以.swiftdoc结尾的文件。 它肯定有文档,因为这些文件包含Swift UIKit / Foundation API的文档,不幸的是,它似乎是一种专有的文件格式,用于Xcode中的文档查看器。
其他回答
是的。基本公共(我用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#>.
*/
我可以确认ShakenManChild已经为人们提供了解决方案
只要确保在描述下面有一个空行!
下面是一些在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";
}
}
上述内容在快速帮助中呈现,正如您所期望的格式化数字列表、项目符号、参数和返回值文档一样。
所有这些都没有被记录下来-档案雷达来帮助他们前进。
从Xcode 5.0开始,支持Doxygen和HeaderDoc结构化注释。
源
也许关注一下AppleDoc或苹果自己的HeaderDoc是个好主意,它不太被认可。 我仍然可以在10.9 Mavericks终端中找到一些HeaderDoc提示(headerdoc2html)
我推荐阅读最新的“Xcode的新功能”*(不确定它是否仍处于保密协议之下) *链接指向Xcode 5.1版本,其中也包含有关HeaderDoc的信息。