swift使用NSClassFromString

/// 在swift中使用NSClassFromString className要加工程名前缀
///
/// - Parameter className: className
func swiftClassFromString(className: String) -> AnyClass! {
    // get the project name
    if  let appName: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String? {
        // YourProject.className
        let classStringName = appName + "." + className
        return NSClassFromString(classStringName)
    }
    return nil;
}
    原文作者:joeal
    原文地址: https://www.jianshu.com/p/5e91d49929a9
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞