问题描述
- iPhone-alloc方法出现问题
-
为了SObject捕捉alloc:NSObject *obj = [[NSObject alloc] init]; UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; NSString *str = [[NSString alloc] init]; [...]
在其他方法中执行都正常,只有在NSObjet的 alloc 有问题。
谁知道原因?
#import "NSObject+Custom.h" #import <objc/runtime.h> @implementation NSObject (Custom) + (void)load { Method original = class_getInstanceMethod(self, @selector(alloc)); Method swizzle = class_getInstanceMethod(self, @selector(allocCustom)); method_exchangeImplementations(original, swizzle); } - (id)allocCustom { NSLog(@"%s", __FUNCTION__); // no way return [self allocCustom]; } @end
时间: 2024-10-02 14:49:18