允许您的类别方法以简短形式存在,例如 MagicalCord MR_SHORTHAND
从 Magical Record 简写中学习代码,并使其更容易使用
例如,我有一个 NSString 的类别
NSString+FTGAdditions.h
@interface NSString (FTGAdditions)
- (void)ftg_doSomething1;
- (void)ftg_doSomething2;
@end
NSString+FTGShorthandAdditions.h
在这里声明您的简写方法,让编译器满意
@interface NSString (FTGShorthandAdditions)
- (void)doSomething1;
- (void)doSomething2;
@end
NSString+FTGAdditions.h
在 load
方法中配置 FTGShorthand
@implementation NSString (FTGAdditions)
- (void)ftg_doSomething1
{
NSLog(@"doSomething1 on %@", self);
}
- (void)ftg_doSomething2
{
NSLog(@"doSomething2 on %@", self);
}
#pragma mark - FTGShorthand
+ (void)load
{
[FTGShorthand setPrefix:@"ftg_"];
[FTGShorthand supportShorthandMethodsForClass:self];
}
@end
supportShorthandMethodsForClass
FTGShorthand 在 MIT 许可下发布。请参阅 LICENSE