Xcode Code Completion

Tue, Mar 5

What follows is a quick review of how I use code completion in Xcode. Chances are that options and features exist beyond what I’ll cover here, so comments and suggestions are welcome.

Let’s say I want to insert a CGRectMake method. I can begin by typing CG and pressing F5 (or Option-esc), which will popup a list of possible matches:

If I choose an entry from this list, Xcode takes care of the rest. If I continue to type characters (instead of hitting F5), Xcode will further narrow the available matches (assuming there is more than one). Again, at any point I can press F5 to bring up the matching list.

As an alternative to using F5 for a list of suggestions, I can hit tab at any point and Xcode will insert the matched text currently displayed. For example, in the figure below I entered CGRe and Xcode inserted the suggestion shown below:

If I’d like to go with this suggestion, pressing the Tab key will insert the code.

Filling in Placeholder Fields
The next step is to fill in any required fields that Xcode has recognized. If there are parameters, Xcode will highlight the first field as shown:

Enter the value you want in the field and press Control / to move to the next field.

Code Sense Preference Settings

If you have any trouble getting these suggestions to work, I’ve included a screenshot of the Code Sense settings that I have configured in Xcode:

In the next post I’ll show how you can use various built-in macros to quickly insert blocks of code.


“pressing F5 (or Command-esc)”

I think you mean Option-Esc; Command-Esc invokes Front Row.

by Mark Glossop on Mar 5, 2009. #

Good catch Mark. Thanks, I’ve made the change to the post.

by john on Mar 5, 2009. #

Great post, I’ve been meaning to write something like this up for a while. Thanks!

by MattjDrake on Mar 5, 2009. #

Thanks for taking the time to post this.

by Matt on Mar 7, 2009. #

Great post. I rebound these keys in preferences to keys on my home row, I use this so frequently.

I have an article up on my blog: http://www.turkeysheartrhinos.com/?p=8 that builds on these concepts and shows you how to create custom macros for code completion.

by Dylan on Mar 25, 2009. #

thanks for this post. it’s mind boggling that ‘code sense’ doesn’t appear in the xcode 3.1.2 help index, and noobs like me have to troll the internet to learn that and are the keys they need.

by noob on May 11, 2009. #

I just started my first app with xCode and I realy needed something like intelisence or something. Now I know that it calls “code sense” in Xcode, and I know how to use it. Thanks.

by other noob on Sep 25, 2009. #

On many of the auto-completions (don’t hit opt-esc or F5 just let the auto complete suggestion show up) if you hit RETURN (instead of tab) it jumps you to the next CamelCased identifier and you can refine from there by typing or hit Return again to jump to the next CamelCased identifier. For example, type NSM and it shows NSMachPort. Hit a u and it shows NSMutableSet Hit Return and it jumps to the Word Set, hit A and you get NSMutableArray.

by Tod on May 6, 2010. #

Another key is Cmd+,

by David Chu on May 11, 2010. #