swift中直接使用NSClassFromString 获取的Class是nil,必须要在类型字符串加入App的执行文件名。“App的执行文件名.类型字符串”
Class MyClassFromString(NSString *className) {
Class c = NSClassFromString(className);
if (c) return c;
NSString *namespace = [[NSBundle mainBundle] infoDictionary][@"CFBundleExecutable"];
c = NSClassFromString([NSString stringWithFormat:@"%@.%@", namespace, className]);
return c;
}
网友评论