Xcode Code Completion

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

Lets 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 Id 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, Ive included a screenshot of the Code Sense settings that I have configured in Xcode:

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

Leave a Reply

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