Xcode Code Completion Macros

Thu, Mar 26

In the previous post I described the basics for working with code completion in Xcode. In this post I will show how you can use built-in text macros to insert various code fragments.

As an example, begin by entering ifelse into Xcode and follow this by pressing Control . (control period) and you’ll see the following code block inserted:

At this point you can add code into the placeholder fields, moving from one field to the next using Control / (control forward-slash).

If you enter a code snippet in which there is more than one possible match, you can cycle through the options by pressing F5 which will bring up a list of options in a popup window, or pressing Command . will cycle through the choices inline in your code.

For example, if you enter if and follow this by pressing F5, you will be shown the window below:

List of Available Macros

The Xcode documentation includes a list of macros available for C, C++ and Objective-C. Some of the macros I use on a regular basis are shown below:

  • nss -> NSString
  • nsms -> NSMutableString
  • nsd -> NSDictionary
  • nsmd -> NSMutableDictionary
  • a -> array (press Control-. to toggle through options)
  • log -> NSLog
  • if -> if else (press Control-. to toggle through options)

Text Macros from the Menu System
Xcode includes a menu of text macros for C, C++, HTML among others. You can find these macros in the Edit menu under Insert Text Macro.

One comment

This is very helpful!

by Vuman on Jul 5, 2010. Reply #

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>