ios类、分类、扩展类 你一定要懂

定义如下分类 x y, 具有相同的函数helloworld

@interface UIImage (x)
- (void)helloworld;
@end
@implementation UIImage (x)
- (void)helloworld {
     NSLog(@"helloworld-A");
}
@end

 ====

@interface UIImage (y)
- (void)helloworld;
@end
@implementation UIImage (y)
- (void)helloworld {
    NSLog(@"helloworld-B");
}
@end

输出结果 完全依赖编译器后编译那个,猜测这种场景 是在编译期间 进行了符号替换!而非增量插入

总结:在确保分类名称唯一的同时,分类中函数 使用前缀  如 - (void)x_helloworld;  - (void)y_helloworld;

原文地址:https://www.cnblogs.com/xzoscar/p/4919434.html