AppCode 2022.2 Help

Extract superclass

The Extract Superclass refactoring enables extracting certain members of a class into a newly created superclass.

Extract superclass

Extract a superclass

  1. Select the desired class in the editor.

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

  3. In the dialog that opens, type the name of the new superclass and select the members that you want to move to the superclass.

  4. Click Extract.

Code examples

Before

After

// All methods of the Dog class // will be moved to a superclass // Dog.h @interface Dog : NSObject - (void)run; - (void)eat; @end // Dog.m @implementation Dog { } -(void)run { NSLog(@"I am running"); } - (void)eat { NSLog(@"I am eating"); } @end
// New superclass // 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 // The Dog class is now a subclass // of the Animal class // Dog.h @interface Dog : Animal @end // Dog.m @implementation Dog { } @end
    Last modified: 21 July 2022