close
將Type轉換成字串的extension
extension String { init<T>(type: T.Type) { self = "\(type.self)" } init<T>(type: T) { self = "\(type(of: type))" } }
使用
let id = String(type: ViewController2.self) let id2 = String(type: self) guard let viewController2 = storyboard?.instantiateViewController(withIdentifier: id) else { return }
Output: "ViewController2"
Output: "ViewController"
全站熱搜
留言列表