如何在Xcode 6中内联代码文档Swift源代码

4
我一直在使用Xcode 5的支持注释语法的功能来记录我的代码(参见此SO问题)。Xcode 6支持Objective-C源文件,但不支持Swift源文件。
我想对.swift源文件进行内联文档。有什么方法或最佳实践吗?
提前致谢,
路易斯

1
Swift有文档注释或工具吗?的副本? - Martin R
2个回答

8

以下是在Xcode 6中记录Swift代码的一些有效方法。虽然它很容易出现错误,并对冒号非常敏感,但总比没有好:

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";
    }
}

上述内容在快速帮助中呈现为格式化的数字列表、项目符号、参数和返回值文档,这是你所期望的。
这些都没有记录 - 提交一个Radar来帮助他们解决。

谢谢,测试时我发现应该在“returns”后面加上“s”,这样解析会更好。 - Luis Palacios

2

看起来您仍然可以添加函数描述:

/**
This is a description of my function
*/
func myFunc() {

}
///this is a description of my second function
func myFunc2(){

}

但目前还不支持任何Headerdoc标签。到Xcode 6发布时可能会得到支持。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接