0
我試圖創造一個迅速擴展情節串連圖板,以更安全的實例化視圖控制器UIStoryboard擴展
protocol IdentifierType {
typealias Identifier: RawRepresentable
}
extension IdentifierType where Self: UIStoryboard, Identifier.RawValue == String {
func instantiateViewControllerWithIdentifier(identifier:Identifier) -> UIViewController {
return self.instantiateViewControllerWithIdentifier(identifier.rawValue)
}
}
,它會不會在編譯時錯誤。但是,當我嘗試執行它時,如:
extension UIStoryboard : IdentifierType {
enum Identifier: String {
case MainViewController = "MAIN_VIEW_CONTROLLER"
case ContactUsViewController = "CONTACT_US_VIEW_CONTROLLER"
case AboutViewController = "ABOUT_VIEW_CONTROLLER"
}
}
發生編譯時錯誤。 「‘標識符’是ambituous在這個上下文類型查找」
謝謝你的回答。這非常簡單。它可以適用於我的情況。我創建了一個Identifier協議,因爲我在UIImage和UIViewControllers中實現了它作爲segueIdentifier。 –