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函数,前者创建指定父类,后者注册

posted on 2016-08-25 23:36  wxm5558  阅读(409)  评论(0编辑  收藏  举报