问题描述
我今天更新到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.
您可以做的是创建一个新的代码片段(包含任何内容,只需将文本拖入在Code Snippet窗口中),然后查找Snippet(宏)的当前格式,并将当前的宏迁移到那里。
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;
as这些文件现在是XML plists。例如,生成 NSLog的简单宏的内容(@Hello护士:%@,
事情 );
键入护士时:
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 <
/ >
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 %@", <#Thing#>);
</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>
请注意,文本宏中缺少Code Snippets的一个方面,就是您以前能够使用的在激活文本宏时定义所选文本的参数(通过在#
之后添加!
,如<#!ReplaceParam!#>
) - 在Code Snippet系统中,似乎没有办法将代码段应用于所选文本,只能拖动它像新的一样。参数仍然可以作为普通参数使用。
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中创建自定义文本宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!