如何创建自定义“文本宏"在Xcode中? [英] How to create custom "Text Macros" in Xcode?

查看:195
本文介绍了如何创建自定义“文本宏"在Xcode中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Xcode中创建自定义代码完成宏.我用谷歌搜索并找到了一些方法,但是我不完全理解它们.谁能告诉我该怎么做?

How to create custom code completion macros in Xcode. I googled and find some methods, but I don't understand them completely. So can anyone tell me how to do it?

谢谢大家.

推荐答案

This post from ablepear has a tutorial to add custom Text Macros. The following are the necessary steps, the tutorial specifies, to create a custom text macro for Objective - C.

  1. 转到您的Xcode应用程序文件(root/Developer/Applications/). 右键单击(按住Control键单击),然后显示包装内容". 导航到(内容/插件/TextMacros.xctxtmacro/内容/资源/). 选择 Objective-C.xctxtmarco 文件并复制(命令-c). 打开一个新的Finder窗口,然后选择您的主文件夹. 导航到(库/应用程序支持/开发人员/共享的/Xcode/). 在Xcode文件夹中粘贴(命令-v)Objective-C.xctxtmacro文件.

  1. Go to your Xcode application file (root/Developer/Applications/). Right-click (control-click) and Show Package Contents. Navigate to (Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources/). Select the Objective-C.xctxtmarco file and Copy it (command-c). Open a new Finder window and select your Home folder. Navigate to (Library/Application Support/Developer/Shared/Xcode/). In the Xcode folder Paste (command-v) the Objective-C.xctxtmacro file.

打开Objective-C.cxtxt宏.它包含一个包含大约26个项目的数组,每个项都是一个词典.单击所选单元格右侧的"+" 符号/标签.这会将一个新项目添加到plist根数组中,这将是我们的新条目(文本宏定义).

Open Objective-C.cxtxtmacro. It contains an Array with around 26 items, each of which is a Dictionary. Click on the "+" symbol/tab to the right of the selected cell. This will add a new Item to the plist root Array which will be our new entry (text macro definition).

选择新项并将类型"从"字符串"更改为字典" .现在点击显示三角形(所选单元格的左侧),这将使三角形从指向右侧(折叠)到指向下方(展开)旋转.您可能还会注意到,展开项目"时,右侧的"+"符号变为一组行.这让我们将儿童" 名称/值对添加到我们的新商品中.

Select the new Item and change the Type from String to Dictionary. Now tap on the disclosure triangle (the left side of the selected cell), this will rotate the triangle from pointing right (collapsed) to pointing down (expanded). You may also notice that the "+" symbol to the right changes into a set of lines when the Item is expanded. This let's us add "children" name/value pairs to our new Item.

我们需要在新项目中添加一些孩子"名称/值对,以使其起作用,它们如下:

There are a few "children" name/value pairs we need to add to our new Item to make it function and they are as follows:

  • 标识符-描述宏的语言(父)标识符.
  • BasedOn -这是(父)语言(objc).
  • IsMenuItem -布尔值.这样会在编辑"菜单中创建一个菜单项.
  • 名称-在(上方)菜单项中监听名称.
  • TextString -将通过文本宏插入的实际字符串.
  • CompletionPrefix -这是您键入的文本宏键.
  • Identifier - This describes the macro's language (parent).identifier.
  • BasedOn - This is the (parent) language (objc).
  • IsMenuItem - Boolean value. This creates a menu item in Edit menu.
  • Name - The name listen in the (above) menu item.
  • TextString - The actual string that will be inserted via the text macro.
  • CompletionPrefix - This what you type in as the key for the text macro.

将值添加到键中.一个典型的宏看起来像这样(例如:NSLog文本宏).

Add the values to the keys. A typical macro looks like this (ex:NSLog text macro).

  • 标识符-objc.博客
  • BasedOn-objc
  • IsMenuItem-是
  • 名称-功能(NSLog)
  • TextString- NSLog(@"FUNCTION:%s",_ FUNCTION _);
  • CompletionPrefix-博客
  • Identifier - objc.flog
  • BasedOn - objc
  • IsMenuItem -YES
  • Name - Function (NSLog)
  • TextString - NSLog(@"FUNCTION: %s", _FUNCTION_);
  • CompletionPrefix - flog

您可以使用任意名称命名Identifier和CompletionPrefix,只要它不与任何现有的完成标识符冲突即可.这里. flog ,用于功能日志.

You can name your Identifier and CompletionPrefix whatever you'd like, as long as it does not conflict with any existing completion identifier. Here. flog, is used for Function Log.

上方阅读文章链接,以全面了解.

重要更新::似乎上述v宏在 Xcode 3.2 中不起作用.要使其正常工作,我们必须添加密钥,

IMPORTANT UPDATE: It seems the above v macro doesn't work in Xcode 3.2. To make it work we have to add the key,

OnlyAtBOL = YES; // or NO 

xctxtmacro文件中的每个宏定义.此项指定宏仅在行的开头 起作用,而不在行的开头起作用,即,仅在行的开头起作用强>.因此 flog 宏将如下所示.

to each macro definition in your xctxtmacro file. This key specifies that the macro works only at Beginning Of Line, or not at the the beginning of line ie., works only after the beginning of line . So the flog macro will look like this.

{
    Identifier = objc.flog;
    BasedOn = objc;
    OnlyAtBOL = YES;
    IsMenuItem = YES;
    Name = "Function (NSLog)";
    TextString = "NSLog(@"FUNCTION: %s", _FUNCTION_)";
    CompletionPrefix = "flog";
}


我希望这对以后的某个人会有帮助.


I hope this will be of some help to someone in future.

这篇关于如何创建自定义“文本宏"在Xcode中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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