AppCode 2021.1 Help

Extract define

The Extract Define refactoring method defines the selected set of tokens as macro using #define directive and replaces the set of tokens with macro call in the code; macro definition can be located in the current file or moved to the related header file.

Extract define

Extract #define

  1. In the editor, select the expression you want to replace with a macro call.

  2. Press ⌃⌥D or select Refactor | Extract/Introduce | Extract Define from the main or context menu.

  3. If there are several expressions available for extracting, select the required one from the list that opens and press .

  4. If more than one occurrence of the selected expression is found, AppCode will suggest replacing all the occurrences or just the selected one. Select the desired option from the list that opens.

  5. Select a name for the macro from the list of suggestions that opens or type a new one.

  6. Select Put to header if you want to move the macro definition to the header file.

Code example

@implementation Screen{ } - (CGPoint)getScreenCenter { // [UIScreen mainScreen].bounds.size will be extracted return CGPointMake(0.5 * [UIScreen mainScreen].bounds.size.width, 0.5 * [UIScreen mainScreen].bounds.size.height); } @end
// Extracted #define #define SCREEN_SIZE [UIScreen mainScreen].bounds.size @implementation Screen{ } - (CGPoint)getScreenCenter { return CGPointMake(0.5 * SCREEN_SIZE.width, 0.5 * SCREEN_SIZE.height); } @end
    Last modified: 08 March 2021