swift3.0 类字符串转类(字符串转ViewController)
来源:互联网 发布:python csv使用 编辑:程序博客网 时间:2024/06/06 03:00
//MARK: -- 根据类文件字符串转换为ViewControllerextension ThirdViewController{ /// 类文件字符串转换为ViewController /// - Parameter childControllerName: VC的字符串 /// - Returns: ViewController func getVCByClassString(_ childControllerName: String) -> UIViewController?{ // 1.获取命名空间 // 通过字典的键来取值,如果键名不存在,那么取出来的值有可能就为没值.所以通过字典取出的值的类型为AnyObject? guard let clsName = Bundle.main.infoDictionary!["CFBundleExecutable"] else { print("命名空间不存在") return nil } // 2.通过命名空间和类名转换成类 let cls : AnyClass? = NSClassFromString((clsName as! String) + "." + childControllerName) // swift 中通过Class创建一个对象,必须告诉系统Class的类型 guard let clsType = cls as? UIViewController.Type else { print("无法转换成UIViewController") return nil } // 3.通过Class创建对象 let childController = clsType.init() return childController }}
阅读全文
0 0
- swift3.0 类字符串转类(字符串转ViewController)
- swift3.0 关于字符串
- Swift3.0 截取字符串
- Swift3.0 字符串
- Swift3.0 字符串
- swift3.0 中字符串截取
- swift3.0 中字符串截取
- swift3.0 字符串和字符
- swift3.0字符串截取,字符串处理
- Swift3.0语法--字符串和字符
- Swift3.0学习笔记----遍历字符串
- swift3.0使用下标截取字符串
- Swift3.0语言教程获取字符串长度
- Swift3.0语言教程获取C字符串
- Swift3.0语言教程比较、判断字符串
- Swift3.0语言教程替换子字符串
- Swift3.0语言教程组合字符串
- Swift3.0语言教程字符串大小写转化
- Apache用户目录枚举工具apache-users
- [置顶]百度贴吧自动回帖的两种方式,使用requests(urllib2)和selenium两种方式回帖
- FPGA静态时序分析——IO口时序(Input Delay /output Delay)
- [置顶]scrapy 知乎关键字爬虫spider代码
- [置顶]使用scrapy_redis,自动实时增量更新东方头条网全站新闻
- swift3.0 类字符串转类(字符串转ViewController)
- H264码流的两种形式:Annex B和AVCC——非常详细的翻译
- wordpress点击文章标题调到站外URL
- python3中字符串、列表、字典的排序
- C++ 整型所能表示的数据范围
- DSP 内联函数(inline)在x86上实现的一些要点之后的验证方法(一)感悟
- 整车厂的四大工艺
- CentOS6自定义服务控制脚本
- Mysql 5.6添加修改用户名和密码