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? P
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.
The directory where they go is:
~/Library/Developer/XCode/UserData/CodeSnippets
In there you'll see files with names like:
E4B300B5-E0EA-4E46-9963-6E9B2111E578.codesnippet
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.
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>
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.