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

查看:9
本文介绍了如何创建自定义“文本宏"在 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?

谢谢大家..

推荐答案

ablepear 的这篇文章 有一个添加自定义文本宏的教程.以下是教程指定的为 Objective - C 创建自定义文本宏的必要步骤.

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/).右键单击(控制单击)并显示包内容.导航到 (Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources/).选择 Objective-C.xctxtmarco 文件并复制它(command-c).打开一个新的 Finder 窗口并选择您的主文件夹.导航到 (库/应用程序支持/开发人员/Shared/Xcode/).在 Xcode 文件夹中粘贴(command-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.cxtxtmacro.它包含一个包含大约 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).

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

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.flog
  • 基于 - objc
  • IsMenuItem -是
  • 名称 - 函数 (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天全站免登陆