AppCode 2021.2 Help

Extract subclass

The Extract Subclass refactoring enables extracting certain members of a class into a newly created subclass.

Extract subclass

Perform the Extract Subclass refactoring

  1. Select the desired class it in the editor.

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

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

Code example

Before

After

// Animal.h @interface Animal : NSObject - (void)meow; - (void)run; - (void)eat; @end // Animal.m @implementation Animal { } // This method will be moved // to a subclass - (void)meow{ NSLog(@"Meow!"); } - (void)run { NSLog(@"I am running"); } - (void)eat { NSLog(@"I am eating"); } @end
// New subclass // Cat.h @interface Cat : Animal - (void)meow; @end // Cat.m @implementation Cat { } - (void)meow{ NSLog(@"Meow!"); } @end // The Animal class // Animal.h @interface Animal : NSObject - (void)run; - (void)eat; @end // Animal.m @implementation Animal { } - (void)run { NSLog(@"I am running"); } - (void)eat { NSLog(@"I am eating"); } @end
    Last modified: 26 August 2021