Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create custom text macros in Xcode 4?

Tags:

xcode

ios4

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

like image 577
Christine Avatar asked Mar 14 '11 19:03

Christine


People also ask

Where do I find Xcode templates?

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.

How to create a Cocoa Touch class from Xcode?

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

What is the size of a Template Icon on Xcode?

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.

What do you use Xcode for?

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.


1 Answers

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 &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>

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.

like image 170
Kendall Helmstetter Gelner Avatar answered Oct 19 '22 22:10

Kendall Helmstetter Gelner