AppCode 2021.2 Help

Extract category

With the Extract Category refactoring you can create a new category based on the members of the current class.

Extract category

Extract a category refactoring

  1. Select the desired class in the editor.

  2. Select Refactor | Extract/Introduce | Category from the main or context menu.

  3. In the dialog that opens, type the name of the new category, select the members that you want to move there, and click Extract.

Code example

BeforeAfter
// Cat.h @interface Cat : NSObject - (void)purr; - (void)meow; @end // Cat.m @implementation Cat { } // This method will be extracted // to a category - (void)purr { NSLog(@"Purr, purr, purr..."); } - (void)meow { NSLog(@"Meow!"); } @end
// New category // Cat+Purr.h @interface Cat (Purr) - (void)purr; @end // Cat+Purr.m @implementation Cat (Purr) - (void)purr { NSLog(@"Purr, purr, purr..."); } @end // Cat.h @interface Cat : NSObject - (void)meow; @end // Cat.m @implementation Cat { } - (void)meow { NSLog(@"Meow!"); } @end
    Last modified: 08 March 2021