Swift NSClassFromString使用

Swift中直接使用NSClassFromString获取的Class是nil,需要在前拼接项目文件名,例如:

NSClassFromString(A.class)
        let model: DataModel = manager.data()[sender.tag]
        
        let workName = Bundle.main.infoDictionary?["CFBundleExecutable"] as! String
        let className: String = model.classField
        
        let class_VC = NSClassFromString("\(workName).\(className)") as! BaseController.Type
        let vc = class_VC.init()
        
        vc.baseTitle = model.title
        self.navigationController?.pushViewController(vc, animated: true)

你可能感兴趣的:(Swift NSClassFromString使用)