相关疑难解决方法(0)

在Swift中返回instancetype

我正在尝试进行此扩展:

extension UIViewController
{
    class func initialize(storyboardName: String, storyboardId: String) -> Self
    {
        let storyboad = UIStoryboard(name: storyboardName, bundle: nil)
        let controller = storyboad.instantiateViewControllerWithIdentifier(storyboardId) as! Self

        return controller
    }
}
Run Code Online (Sandbox Code Playgroud)

但我得到编译错误:

错误:无法将'UIViewController'类型的返回表达式转换为返回类型'Self'

可能吗?我也想成为init(storyboardName: String, storyboardId: String)

swift swift-extensions swift2

35
推荐指数
2
解决办法
1万
查看次数

标签 统计

swift ×1

swift-extensions ×1

swift2 ×1