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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -