美文网首页iOS开发
swift使用NSClassFromString

swift使用NSClassFromString

作者: joeal | 来源:发表于2018-06-29 11:46 被阅读70次
/// 在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;
}

相关文章

网友评论

    本文标题:swift使用NSClassFromString

    本文链接:https://www.haomeiwen.com/subject/jfxayftx.html