ios - Infer type to generics from function's return type -
i have storyboard , view controllers in it. storyboard id of every view controllers same class name assigned it. like: walkthrough view controller assigned walkthroughvc class , storyboard id walkthroughvc.
i made function below, instance of view controller storyboard:
func getviewcontroller<t: uiviewcontroller>() -> t? { let sb = uistoryboard(name: "main", bundle: nil) sb.instantiateviewcontrollerwithidentifier(viewcontroller.rawvalue) as? t }
is possible infer type of t? if yes, how?
i think looking for.
class viewcontrollers { class func getviewcontroller<t : uiviewcontroller>(fromstoryboard : string, fromclass : t) -> t? { let storyboard = uistoryboard(name: fromstoryboard, bundle: nil) let controller = storyboard.instantiateviewcontrollerwithidentifier("\(fromclass)") as? t return controller } }
Comments
Post a Comment