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.
This is the directory where I currently have my 'ObjectiveC.xctxtmacro' file. ~/Library/Application Support/Developer/Shared/Xcode/Specifications
Each Xcode custom template files are located in ~/Library/Developer/Xcode/Templates/ and grouped into segments by folder name. You can add it manually or using the terminal by running the following command: Every XCode file template is a distinct folder with the extension .xctemplate.
For instance, the Cocoa Touch Class template is located under File Templates > Source > Cocoa Touch Class.xctemplate. There, you can find all the template files for all the possible options that you have when creating a Cocoa Touch Class from Xcode. But, if you want to add your own custom template, this directory is not the proper one. Instead, use
For a template to be visible on Xcode it is required to have three files, the TemplateInfo.plist, TemplateIcon.png and [email protected]. The TemplateIcon.img is a 48x48 image whereas the [email protected] is a 96x96 image and are the thumbnails that will be presented in the template selection window on Xcode.
With Xcode, every day we create files and groups. As a developer improving work processes is always on their mind. We need tools and solutions to speed up the coding, testing, or organizing of our work. We usually create files for our classes, storyboards, or XIBs. We organize them into folders to have a logically organized project.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With