Learn to use Xcode 4 snippets

Code Snippets

One of my favorite features of the new Xcode 4 is code snippets. Code snippets let you use (and re-use) common classes and objects by simply typing a shortcut. For example if you type dealloc, Xcode 4 automatically generates the deallocation method for you:

- (void)dealloc {

<#deallocations#>

[super dealloc];

}

To add your code snippets to Xcode:

  1. Find the code you want and highlight it.
  2. Drag the selected code to the the Snippet Library
  3. Name your snippet (this is just the name you see in the Snippet Library)
  4. Choose a shortcut for your snippet which is used to invoke it (a good practice is to use shortcuts that show what the snippet does, like dealloc is used for invoking the deallocation method).
  5. Choose language and platform (so Xcode knows when to offer this snippet).
  6. If you like a bubble to appear as part of your snippets (like the #deallocations# in the example), just type: <#text in the bubble#> in your snippet.
Tagged on: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *