自己做的,测试没有问题
- 再plist文件中要加项目名称才可以实现内容
如: WeChat.ChatViewController
func getNavigateToViewController(_ classNameKey: String) {
if let fileURL = Bundle.main.url(forResource: "VCDataList", withExtension: "plist") {
do {
let data = try Data(contentsOf: fileURL)
let plist = try PropertyListSerialization.propertyList(from: data, options: .mutableContainers, format: nil) as! Dictionary<String, Any>
debugPrint("dataDicdataDic plist== \(plist)")
let dataDic = plist["className"] as! Dictionary<String, Any>
debugPrint("dataDicdataDic == \(dataDic)")
let baseViewController = dataDic["VC"]
let className = NSClassFromString(baseViewController as! String) as? SSTBaseViewController.Type
let viewController = className?.init()
self.navigationController?.pushViewController(viewController! , animated: true)
} catch {
// 处理文件读取错误
print("文件读取错误: \(error)")
}
} else {
// 处理文件不存在的情况
print("文件不存在")
}
}