自己做的,測試沒有問題
- 再plist文件中要加項(xiàng)目名稱才可以實(shí)現(xiàn)內(nèi)容
如: 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 {
// 處理文件讀取錯(cuò)誤
print("文件讀取錯(cuò)誤: \(error)")
}
} else {
// 處理文件不存在的情況
print("文件不存在")
}
}