查看命名空间
- 命名空间默认是项目名称,但是可以修改命名空间
- info.plist文件->选中Executable file->单击右键选择property list type->选择none
3.命名空间就存储CFBumdleExecutable键值中
代码实现
//0.动态获取命名空间
let ns = Bundle.main.infoDictionary!["CFBundleExecutable"] as! String
//1.将字符串转化为类,默认情况下命名空间是项目名称,项目名称是可以修改的
let cls:AnyClass? =NSClassFromString(ns+"."+childControllerName)
//2.通过类创建对象,将AnyClass转化为指定类型
let vcCls = cls as! UIViewController.Type
let vc = vcCls.init()
print(vc)
运行结果:
<FQweibo.ProfileTableViewController: 0x7f9ce3f0a210>
修改命名空间
选择项目->选择build settings->搜索product name->点击项目名称就可以进行修改