Auto generate method comment in Xcode
You can use shortcut for create header doc:
⌘ + ⌥ + /
where
⌘ = Command
⌥ = Option (Alt on Windows compatible keyboards)
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.)
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.)
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.
Not ideal but it's better than nothing. Snippets are a nice idea that Apple haven't quite finished implementing yet.
-
Select your code for which you want to generate comment and press shortcut key
CMD + ALT + /
Comment will be autogenerated for selected method.
You can use a comment syntax to generate a doc
Editor -> Structure -> Add Documentation
⌘ command ⌥ option /
/// <#Description#>
///
/// - Parameter param: <#param description#>
/// - Returns: <#return value description#>
/// - Throws: <#throws value description#>
func fun(param: String) throws -> String? {
return false;
}
Official Markup Formatting Reference
You can use this awesome plugin.
https://github.com/onevcat/VVDocumenter-Xcode