Extract category
With the Extract Category refactoring you can create a new category based on the members of the current class.
Extract a category refactoring
Select the desired class in the editor.
Select
from the main or context menu.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
Before | After |
---|---|
// 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: 05 April 2022