实例方法的动态方法解析

2021-07-08  本文已影响0人  Jean_Lina
- (void)sing;
- (void)singSong {
    NSLog(@"%s", __func__);
}
#pragma mark 实例方法的动态方法解析
+ (BOOL)resolveInstanceMethod:(SEL)sel {
    if (sel == @selector(sing)) {
        Method method = class_getInstanceMethod(self, @selector(singSong));
        class_addMethod(self, sel, method_getImplementation(method), method_getTypeEncoding(method));
        return YES;
    }
    return [super resolveInstanceMethod:sel];
}

上一篇 下一篇

猜你喜欢

热点阅读