Consider this pattern
extension UIViewController
{
class func make(sb: String, id: String) -> Self
{
return helper(sb:sb, id:id)
}
private class func helper<T>(sb: String,id: String) -> T
{
let s = UIStoryboard(name: storyboardName, bundle: nil)
let c = s.instantiateViewControllerWithIdentifier(id) as! T
return c
}
}
that works fine, so
let s = SomeViewControllerClass.make( ... )
does in fact return the subclass "SomeViewControllerClass". (Not just a UIViewController.)
That's all fine BUT,
say in make
you want to do some setup:
class func make(sb: String, id: String) -> Self
{
let h = helper(sb:sb, id:id)
// some setup, m.view = blah etc
return h
}
in fact it appears you cannot do that.
You can only
return helper(sb:sb, id:id)
you cannot
let h = helper(sb:sb, id:id)
return h
is there a solution?