Extract constant
Last modified: 26 January 2023Language: Objective-C
Shortcut: Ctrl+Alt+C
The Extract Constant refactoring helps you avoid using hardcoded constants without any explanations about their values or purpose.

Extract a constant
In the editor, select an expression or declaration of a variable you want to replace with a constant.
Press Ctrl+Alt+C to introduce a constant or select Refactor | Extract/Introduce | Constant from the main or context menu.
If there are several expressions available for extracting, select the required one from the list that opens and press Enter.
Select a name for the constant from the list of suggestions that opens or type a new one.
Check the Put to header checkbox if you want the constant to be moved to the header file.
Uncheck the Declare static checkbox if you don't want the constant to be declared as
static
.Press Enter.
Before | After |
---|---|
|
|
Thanks for your feedback!