2 daffodilgirl DaffodilGirl 于 2013.06.03 13:35 提问

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
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!