import <objc/runtime.h>
- (void)createClass
{
Class newClass = objc_allocateClassPair([NSString class], "NSStringSubclass", 0);
class_addMethod(newClass, @selector(report), (IMP)ReportFunction, "v@:");
objc_registerClassPair(newClass);
id instanceOfNewClass = [[newClass alloc] init];
[instanceOfNewClass performSelector:@selector(report) withObject:@"hello"];
}
void ReportFunction(id self, SEL _cmd, NSString *test) {
NSLog(@"This object is %p.", self);
NSLog(@"Class is %@, and super is %@.", [self class], [self superclass]);
NSLog(@"ReportFunction:参数:%@",test);
}
网友评论