我可以添加自己的代码片段到xcode 4吗? [英] Can I add my own code snippets to xcode 4?

查看:108
本文介绍了我可以添加自己的代码片段到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比其他解决方案(如全局系统文本扩展器)更好的一点是,片段也可以限制为在某个区域的代码中有效 - 例如,填充字符串格式化行的片段可以标记为仅有效在一个块内,不在方法之外。这样,完成前缀只能在有效使用的区域中输入。

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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆