一道iOS面试题?

故事背景:
这个是自己在复习KVO时,偶然想到的(就是虾基霸写的),类似的面试题应该有小伙伴遇到过~

@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    Person *p = [Person new];
    [p setValue:@"aa" forKey:@"name"];
    [p addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];

    Method m = class_getInstanceMethod([self class], @selector(log));
    const char *className = object_getClassName(p);
    NSString *name = [[NSString alloc] initWithUTF8String:className];
    class_addMethod(NSClassFromString(name), method_getName(m), method_getImplementation(m), method_getTypeEncoding(m));
    
    [p performSelector:@selector(log)];
}

- (void)log
{
    NSLog(@"self: %s", object_getClassName(self));
}

@end

代码如上
问题:方法log会打印什么?

PS:该题涉及到KVO原理,消息发送原理以及类结构中的ISA指针三个知识点

你可能感兴趣的:(一道iOS面试题?)