Skip to content

Instantly share code, notes, and snippets.

@nbessi
Created August 12, 2010 16:00
Show Gist options
  • Save nbessi/521200 to your computer and use it in GitHub Desktop.
Save nbessi/521200 to your computer and use it in GitHub Desktop.
Xcode 4 custom snippet
If you want to make your own custom snippets with in preview version of Xcode 4 and do not want to wait for the function to be implemented here is the way :
Open the folder ~/Library/Developer/Xcode/UserData/CodeSnippets
Create a file named my_nice_file.codesnippet (one file per snippet)
It should look like this : http://gist.github.com/521183
There is only one rule to respect :
the value of the key should be unique in all files
<key>IDECodeSnippetIdentifier</key>
<string>myUniqueValue</string>
then you have two choices :
-Restart Xcode and edit you custom snippet directly from Xcode.
-Edit the file manually
If you choose the second choice the first thing to do is to create the content of your snippet inside the IDECodeSnippetContents key :
<key>IDECodeSnippetContents</key>
<string>class &lt;#MyClass#&gt;(osv.osv):
" &lt;#DOCString#&gt;"
#_name="My name"
_inherit = '&lt;#module.object#&gt;'
_description = __doc__
_columns = {
}
&lt;#MyClass#&gt;()</string>
The place holder are define with the following syntax : <#my name#>.
Be sure to encode the entities inside the template or you will have a bad surprise.
All the other values can be easily deducted from the sample file.
My two cents
Nicolas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment