简体   繁体   English

Xcode评论自动完成(appledoc风格)

[英]Xcode comments autocompletion (appledoc style)

I find documentating my interfaces particularly painful because I need to type everything myself. 我发现记录我的界面特别痛苦,因为我需要自己输入一切。 So I figured that I must not be the only one like this and started to look for a way to reduce my pain but didn't find much. 所以我认为我不应该是唯一一个这样的人,并开始寻找一种方法来减轻我的痛苦,但没有找到太多。

My question is, is there a shortcut or a way to have Xcode autocomplete my comments? 我的问题是,是否有一个快捷方式或方法让Xcode自动完成我的评论? For example, I'd very much like if I type /** + [tab] that it autocompletes to: 例如,我非常喜欢输入/** + [tab]它自动填充到:

/**
 * [cursor here]
 * 
 * (maybe some pre-populate a list of arguments for the method below)
 */
- (void)test:(NSString *)testString another:(NSString *)another;

Thanks! 谢谢!

Use Xcode's snippets feature. 使用Xcode的代码段功能。 You can create a snippet with whatever text you want, and add items in the text to be filled in. To create a snippet, just select some text in an Xcode editor and drag it into the snippet library. 您可以创建包含所需文本的代码段,并在要填写的文本中添加项目。要创建代码段,只需在Xcode编辑器中选择一些文本并将其拖到代码段库中。 You can set the completion shortcut, so something like m-comment could be your standard method comment: 您可以设置完成快捷方式,因此m-comment可能是您的标准方法注释:

片段编辑器

Typing the first bit of m-comment then displays the entire shortcut (and any other completions), and accepting the completion adds a comment with the parameterized parts waiting to be filled in. As usual, you can tab from one to the next: 键入m-comment的第一位然后显示整个快捷方式(以及任何其他完成),并接受完成添加注释,参数化部分等待填写。像往常一样,您可以从一个选项卡到下一个:

插入评论

You indicate that a given part of the text is a field to be filled in by enclosing it in <# and #> , like: <#method name#> . 您指示文本的给定部分是要填写的字段,方法是将其<#method name#><##> ,例如: <#method name#>

Of course, one of the strengths of Objective-C is that the method name generally tells you what the parameters are. 当然,Objective-C的优势之一是方法名称通常会告诉您参数是什么。 Repeating that in a comment seems like unnecessary extra work. 在评论中重复这一点似乎是不必要的额外工作。 Xcode 3 had better support for scripts included scripts that would automatically generate HeaderDoc comments with parameters. Xcode 3更好地支持包含脚本的脚本,这些脚本会自动生成带参数的HeaderDoc注释。 They weren't widely used, though, probably because those kinds of comments weren't really useful. 但是,它们并没有被广泛使用,可能是因为这些评论并没有真正有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM