本文介绍了我可以将自己的代码片段添加到 xcode 4 中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 xcode 中收集 KVC 访问器片段会非常方便,因为手动完成它们很痛苦.有没有人已经使用了一段时间的 4 想出了如何添加新的?

It'd be really handy to have collection KVC accessor snippets in xcode, as they're a pain to do by hand. Has anyone who's been using 4 for a while worked out how to add new ones?

(……我们现在可以谈论它了,对吧?)

(...we're allowed to talk about it now, right?)

推荐答案

是的,这很容易 - 您只需突出显示要用作片段的文本并将其拖到片段区域(拖动选定的文本可能很困难,我如果从编辑器的左边缘拖动,效果会更好).它会弹出一个对话框,要求您为其命名.

Yes, it's quite easy - you just highlight text you want to use as a snippet and drag it into the snippets area (dragging selected text can be difficult, I find it works better if you drag from the left edge of the editor). It brings up a dialog box asking you to name it.

此外,您可以在代码段中使用自定义参数 - 如果您将文本 <#paramName#> 放在要拖动的代码中的任何位置,当您使用代码段时,它会显示为一个可替换的参数,您可以像在官方代码段中一样在它们之间切换.

Also, you can have custom parameters in snippets - if you put the text <#paramName#> anywhere in the code you are dragging, when you use the snippet it will come up as a replaceable parameter that you can tab between just like in the official Snippets.

还要确保设置完成前缀,这样可以缩短在您键入时激活代码段的时间.与全局系统文本扩展器等其他解决方案相比,使用 Snippets 的好处是,snippets 也可以限制在特定代码区域中有效 - 例如,填充字符串格式行的代码段可以标记为仅有效在块内,而不是在方法外.这样,完成前缀只会在有效使用的区域中起作用.

Also make sure to set a completion prefix, which makes it shorter to activate the snippet as you are typing. The nice thing about using Snippets over other solutions like global system text expanders, is that snippets can also be limited to being valid in a certain area of code - so for example a snippet that filled out a string formatting line can be marked as valid only within a block, not outside a method. That way the completion prefix only hits in areas where it's valid to use.

您可以通过单击一次来编辑代码段,一个框将显示代码段文本和您可以编辑的其他一些代码段设置.

You can edit a snippet by clicking once on it, a box will come up with the snippet text and some other snippet settings you can edit.

这篇关于我可以将自己的代码片段添加到 xcode 4 中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:17