AppCode 2023.1 Help

Extract typedef

The Extract Typedef refactoring changes the selected declaration of a type to a typedef definition. You can apply Extract Typedef when actual declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another, or just to make code presentation more clear and readable.

Extract typedef

Extract a typedef definition

  1. In the editor, select the type declaration to be re-declared.

  2. Press Ctrl+Alt+K or select Refactor | Extract/Introduce | Typedef 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 Enter.

  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 typedef from the list of suggestions that opens or type a new one.

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

Code example

Before

After

@interface LoginModel : NSObject - (void)loginWithEmail:(NSString *)email password:(NSString *)password // void (^)(BOOL success) will be extracted to a typedef completion:(void (^)(BOOL success))completion; @end
// Extracted typedef typedef void (^LoginModelCompletion)(BOOL); @interface LoginModel : NSObject - (void)loginWithEmail:(NSString *)email password:(NSString *)password completion:(LoginModelCompletion)completion; @end
Last modified: 16 December 2022