ios-runtime面试题

1. 输出结果是啥,会不会崩溃?
//MNPerson
@interface MNPerson : NSObject
@property (nonatomic, copy)NSString *name;
- (void)print;
@end

@implementation MNPerson
- (void)print{
    NSLog(@"self.name = %@",self.name);
}
@end
---------------------------------------------------
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    id cls = [MNPerson class];
    void *obj = &cls;
    [(__bridge id)obj print];
}
---------------------------------------------------
打印结果:self.name = 

考察内存分配
参考一道高级iOS面试题(runtime方向)

你可能感兴趣的:(ios-runtime面试题)