如何在 Xcode 4 中创建自定义文本宏? [英] How do I create custom text macros in Xcode 4?

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

问题描述

我今天更新到 Xcode 4,我的自定义文本宏不再起作用.我找不到有关如何在 Xcode 4 中使用自定义宏的任何信息.这仍然可能吗?请让我知道是否有人提出了解决方案.

I updated to Xcode 4 today and my custom text macros are no longer working. I cannot find any information on how to use custom macros with Xcode 4. Is this still possible? Please let me know if anyone has come up with a solution.

这是我目前拥有ObjectiveC.xctxtmacro"文件的目录.~/Library/Application Support/Developer/Shared/Xcode/Specifications

This is the directory where I currently have my 'ObjectiveC.xctxtmacro' file. ~/Library/Application Support/Developer/Shared/Xcode/Specifications

推荐答案

文本宏的定义格式以及它们的位置发生了变化 - 文本宏已经变成了代码片段.

The format of how Text Macros are defined, and where they live has changed - Text Macros have morphed into Code Snippets.

您可以做的是创建一个新的代码片段(任何东西,只需将文本拖到代码片段窗口中),然后去寻找片段(宏)的当前格式,并将您当前的宏迁移到那里.

What you can do is make a new code snippet (with anything, just drag text into the Code Snippet window), then go looking for the current format of a Snippet (Macro), and migrate your current macros into there.

他们去的目录是:

~/Library/Developer/XCode/UserData/CodeSnippets

在那里,您会看到名称如下的文件:

In there you'll see files with names like:

E4B300B5-E0EA-4E46-9963-6E9B2111E578.codesnippet

很棒的是,您不必使用 UUID 名称 - 我能够将其中一个复制到一个名为MyTest.codesnippet"的文件中,XCode 仍然可以读取它.

The great thing is, you don't have to use UUID names - I was able to copy one of those into a file called "MyTest.codesnippet" and XCode still reads it.

因此,每个现有宏都有一个文件(因为旧的 .xctxtmacro 文件中通常有许多宏),您可以按原样使用实际的宏文本,因为参数语法没有改变(尽管所有宏周围的元数据发生了很大变化).您将不得不转换<"/">" 定义为 XML 安全语法 &lt;/&gt; 的任何参数的部分,因为文件现在是 XML plist.例如,一个简单的宏的内容产生 NSLog(@"Hello Nurse: %@",Thing); 当 "nurse" 输入:

So you'd have one file per existing macro (as there are usually a number of macros in the older .xctxtmacro files), you can use the actual macro text as-is as the parameter syntax has not changed (although all of the meta-data around a macro has changed substantially). You will have to convert the "<" / ">" parts of any parameters defined to XML-safe syntax &lt; / &gt; as the files are XML plists now. As an example, the contents of a simple macro that produces NSLog(@"Hello Nurse: %@",Thing); when "nurse" is typed:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>IDECodeSnippetCompletionPrefix</key>
    <string>nurse</string>
    <key>IDECodeSnippetCompletionScopes</key>
    <array>
        <string>All</string>
    </array>
    <key>IDECodeSnippetContents</key>
    <string>NSLog(@"Hello Nurse %@", &lt;#Thing#&gt;);
</string>
    <key>IDECodeSnippetIdentifier</key>
    <string>E4B300B5-E0EA-4E46-9963-6E9B2111E579</string>
    <key>IDECodeSnippetLanguage</key>
    <string>Xcode.SourceCodeLanguage.Objective-C</string>
    <key>IDECodeSnippetTitle</key>
    <string>TestNurse</string>
    <key>IDECodeSnippetUserSnippet</key>
    <true/>
    <key>IDECodeSnippetVersion</key>
    <integer>2</integer>
</dict>
</plist>

请注意,文本宏中缺少的代码片段的一个方面是,您过去能够定义激活文本宏时所选文本所在的参数(通过在之后添加 !#<#!ReplaceParam!#> 中一样) - 在代码片段系统中,似乎没有办法将代码片段应用于选定的文本,您只能将其拖出为新的.不过,这些参数仍然可以作为普通参数使用.

Note that one aspect of Code Snippets that is missing from Text Macros, is that you used to be able to define parameters where selected text would go when you activated a Text Macro (by adding ! after the # as in <#!ReplaceParam!#> ) - in the Code Snippet system, there does not appear to be a way to apply a Code Snippet to selected text, you can only drag it out as new. The parameters still work as normal parameters though.

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

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