swift使用NSClassFromString

2019-08-23 18:03:09 浏览数 (1)

代码语言:javascript复制
/// 在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;
}

0 人点赞