在 Xcode 中自动生成方法注释
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8954087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto generate method comment in Xcode
提问by Laszlo
Is there a way in Xcode to generate method comment automatically similar to what you do in Eclipse for javadoc comments.
Xcode 中是否有一种方法可以自动生成方法注释,类似于您在 Eclipse 中为 javadoc 注释所做的操作。
For example press you may hit /** one row before a method declaration and eclipse automatically generates the skeleton of method comments.
例如,在方法声明前按 /** 一行,eclipse 会自动生成方法注释的骨架。
采纳答案by Tim
You can use the Code Snippets library for this. It won't automatically generate placeholders for each parameter, but it's pretty useful nonetheless. Here's what you do:
您可以为此使用代码片段库。它不会自动为每个参数生成占位符,但它仍然非常有用。这是你要做的:
- Write out a sample comment block in your code somewhere.
- Insert
<#xyz#>
where you want a placeholder named 'xyz' to appear. (These are like parameter completion placeholders, so you can tab between them and overwrite them.)
- 在代码中的某处写出示例注释块。
<#xyz#>
在您希望出现名为“xyz”的占位符的位置插入。(这些就像参数完成占位符,因此您可以在它们之间切换并覆盖它们。)
For example:
例如:
/**
* Method name: <#name#>
* Description: <#description#>
* Parameters: <#parameters#>
*/
- Open up the right hand sidebar. In the bottom pane click on the two curly braces icon to bring up the snippets library.
- Select and drag your text to the code snippets library.
- It'll create a new one. Double click on it, click edit in the popup, and give it a completion shortcut (e.g. comblk for comment block.)
- 打开右侧边栏。在底部窗格中,单击两个花括号图标以显示代码段库。
- 选择您的文本并将其拖到代码片段库中。
- 它将创建一个新的。双击它,在弹出窗口中单击编辑,并给它一个完成快捷方式(例如,comblk 用于注释块。)
Now, when you type 'comblk' anywhere in your editors, the autocomplete popup appears and you can hit return to paste in the snippet. The first placeholder will be selected and you can start typing the method's name. Hit tab to switch to description, and so on.
现在,当您在编辑器的任意位置键入“comblk”时,会出现自动完成弹出窗口,您可以按回车键粘贴代码段。将选择第一个占位符,您可以开始键入方法的名称。点击选项卡切换到描述,依此类推。
Not ideal but it's better than nothing. Snippets are a nice idea that Apple haven't quite finished implementing yet.
不理想,但总比没有好。片段是一个不错的主意,但 Apple 尚未完全实施。
回答by Tomas Ivan
You can use shortcut for create header doc:
您可以使用快捷方式创建标题文档:
? + ? + /
? + ? +/
where
? = Command
? = Option (Alt on Windows compatible keyboards)
其中
? = Command
? = Option(Windows 兼容键盘上的 Alt)
回答by pallavi
Select your code for which you want to generate comment and press shortcut key
CMD + ALT + /
Comment will be autogenerated for selected method.
选择您要为其生成注释的代码并按快捷键
CMD + ALT + /
将为所选方法自动生成注释。
回答by smokingoyster
回答by yoAlex5
You can use a comment syntax to generate a doc
您可以使用注释语法来生成文档
Press ? command+? option+/or Editor -> Structure -> Add Documentation
按? command+ ? option+/或Editor -> Structure -> Add Documentation
/// <#Description#>
///
/// - Parameter param: <#param description#>
/// - Returns: <#return value description#>
/// - Throws: <#throws value description#>
func fun(param: String) throws -> String? {
return false;
}
Read more Markup Formatting Reference
阅读更多标记格式参考