iOS动态的创建类
- (Class)createClass:(NSString*)className{ NSString* kLXDkvoClassPrefix= @"NSKVONotifying_"; NSString * kvoClassName = [kLXDkvoClassPrefix stringByAppendingString: className]; Class observedClass = NSClassFromString(kvoClassName); if (observedClass) { return observedClass; } Class kvoClass = objc_allocateClassPair(NSClassFromString(className), kvoClassName.UTF8String, 0); objc_registerClassPair(kvoClass); return kvoClass; }
主要是两个函数objc_allocateClassPair函数,以及objc_registerClassPair函数,前者创建指定父类,后者注册