Wednesday, November 9, 2011

Xcode 4 : Select and Edit All Variables in Scope


Xcode offers a nice way to highlight all references of a variable within the current scope. First, make sure you have the setting shown below enabled within the Text Editing tab in the Xcode Preferences:


Now, select a variable within your code, and notice that all references within the current scope will be highlighted. For example, below I selected (double tapped) username and all references are now underlined.

In the above figure notice the drop down arrow next to the first instance that I referenced. Tapping this arrow brings up an dialog, given the configuration of my system, the dialog looks as follows:

The values in your dialog may be different based on your system configuration.
If you choose the Edit All in Scope, Xcode will highlight all references and allow you to change the name of the selected variable. Changes will cascade through to each reference of the variable.

Using this tip you can quickly change all references to a variable in the current scope, watching the changes take place as you type.

No comments:

Post a Comment