swift 通过字符串名转化成类 (NSClassFromSt

2018-12-04  本文已影响10人  目染江夏
let preStr = Bundle.main.infoDictionary?["CFBundleExecutable"] as? String
        log("prestr: \(String(describing: preStr))")
if var _preStr = preStr {
  //如果项目名中有  — 需要做一下 替换 ,否则不需要
  _preStr =  _preStr.replacingOccurrences(of: "-", with: "_")
   let vcClass = NSClassFromString(_preStr + vcTitleArr[indexPath.row]) as! UIViewController.Type
   let vc = vcClass.init()
   self.navigationController?.pushViewController(vc, animated: true)
  }
上一篇下一篇

猜你喜欢

热点阅读