有没有一种标准的方法来编写Swift语言的文档注释?相当于javadoc(Java)或docstrings(Python)的东西?
例:
/**
* My docstring example
* @return the String "foo"
*/
func foo() -> String {
return "Foo"
}
Run Code Online (Sandbox Code Playgroud)
Jea*_*nan 14
就在这里.
Swift包含"///"注释处理(尽管可能还不是所有内容).
写下类似的东西:
/// Hey!
func bof(a: Int) {
}
Run Code Online (Sandbox Code Playgroud)
然后选择 - 点击func名称和voilà:)
有两种类型的文档注释单行"/// ..."和多行"/**...*/"文档NSHipster在这里解释它
从网站复制的示例代码:
/**
Repeats a string `times` times.
- Parameter str: The string to repeat.
- Parameter times: The number of times to repeat `str`.
- Throws: `MyError.InvalidTimes` if the `times` parameter
is less than zero.
- Returns: A new string with `str` repeated `times` times.
*/
func repeatString(str: String, times: Int) throws -> String {
guard times >= 0 else { throw MyError.InvalidTimes }
return Repeat(count: 5, repeatedValue: "Hello").joinWithSeparator("")
}
Run Code Online (Sandbox Code Playgroud)