产品构建框架需要,涉及到动态调用,所以了解了下,做下简单的底层记录:
1.搜索类列表方式:
Person *person = [[NSClassFromCaseInsensitiveString("Person") alloc] init];
Person *person = NSClassFromString(personString);
2.自定义字典方式:
NSDictionary * classesByLowercaseString = [NSDictionary dictionaryWithObjectsAndKeys:
[Person class], @"person",
[Blah class[, @"blah",
nil];
[classesByLowercaseString objectForKey:[xmlClassName lowercaseString]];
3.objc_getClass等底层方法
手册:http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html
id objc_getClass(const char *name)
Class myClass = objc_getClass(myClassName);
if(myClass){
id myObject = class_createInstance(myClass,0);
objc_msgSend(myObject, @selector(doSomethingWith:andWith:alsoWith:), firstP, secondP,thirdP);
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10531/viewspace-712279/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10531/viewspace-712279/