The Extract Constant refactoring makes your source code easier to read and maintain. It also helps you avoid using hard-coded constants without any explanations about their values or purpose.
Extracting a Objective-C constant in-place
To extract a Objective-C constant in-place
- Place the cursor within the expression or declaration of a variable to be replaced by a constant.
- Do one of the following:
- Choose Refactor | Extract | Constant on the context menu.
- If more than one expression is detected for the current cursor position, the Expressions list appears. If this is the case, select the required expression. To do that, click the expression. Alternatively, use the Up and Down arrow keys to navigate to the expression of interest, and then press N/A to select it.
- If more than one occurrence of the expression is found within the class, specify whether you wish to replace only the selected occurrence, or all the found occurrences with the new constant.
- If you want the constant to be defined in the header file, select the Put to header check box.
- Specify the name of the constant. Select the name from the list or type the name in the box with a red border.
- To complete the refactoring, press N/A orN/A.
If you haven't completed the refactoring and want to cancel the changes you have made, press N/A.