如何将自定义代码片段添加到XCode 4? [英] How to add custom code snippets to XCode 4?

查看:98
本文介绍了如何将自定义代码片段添加到XCode 4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在XCode窗口的最右侧显示工具窗格,然后选择{}按钮,它会显示您可以键入快捷方式的代码段,或者拖放到源代码中。你如何创建自己的?

If you show the Utilities pane on the far right of the XCode window, then select the "{ }" button, it shows code snippets that you can type the shortcut for, or drag and drop into your source code. How do you create your own?

推荐答案

虽然文档很少,但我发现 Jason Brennan的博客文章,逐步介绍。

Although the documentation is very scant on this, I did find a blog post by Jason Brennan that describes step-by-step.


  1. 输入您要为其创建代码段的代码。

  2. 突出显示代码。

  3. 拖动突出显示的代码并将其放在Snippet实用程序部分。

  4. 单击该代码段,将出现一个弹出标题对话框。编辑标题,说明和快捷方式。

  1. Type in the code you want to create a snippet for.
  2. Highlight the code.
  3. Drag the highlighted code and drop it on the Snippet utility section.
  4. Click the snippet, a popup caption dialog will appear. Edit the title, description, and shortcut.

注意:您可以使用由<#prompterName#>表示的提示符来提供蓝色您可以选中的气泡,并替换为源中的参数。例如:

NOTE: You can use prompters denoted by <#prompterName#> that will give blue bubbles that you can tab to, and replace with "parameters" in your source. For example:

NSDictionary *< #varibleName#> = [[NSBundle mainBundle] infoDictionary];

NSDictionary *<#varibleName#> = [[NSBundle mainBundle] infoDictionary];

注意:根据您正在编辑的源代码文件的语言,您的新代码段将默认使用该语言。这样,根据您的上下文,片段有选择地用于Swift或Objective-C。

NOTE: Depending on the language of the source code file you are editing, your new snippet will default to be in that language. In this way, snippets are selectively used for Swift or Objective-C depending on your context.

注意:如果您尝试拖动突出显示的文本,它会取消选择并启动相反,选择新选项,尝试在所选文本右侧的空白处开始拖动操作。

NOTE: If you attempt to drag highlighted text, and it unselects and starts a new selection instead, try to start your drag action in the whitespace off to the right of your selected text.

此外,要删除您的代码段,请单击以在代码段中突出显示库,然后按删除键。

Also, to delete your snippets, click to highlight in the snippet library, and press the "Delete" key.

这篇关于如何将自定义代码片段添加到XCode 4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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