I have a method in objective-c which takes string and converting to class and passing some common object to it.
-(UIViewController*)getUIViewController{
NSString* templateID = @"templateId"; // This value is coming from ba ckend
Class c = NSClassFromString(templateID);
UIViewController* vc = [[c alloc] initWithAppRender:appRenderer];
return vc;
}
Now the same thing converting to swift.
func getUIViewController() -> UIViewController? {
let templateID = "templateId"
let className = Bundle.main.infoDictionary!["CFBundleName"] as! String + "." + templateID
let aClass = NSClassFromString(className) as! UIViewController.Type
return aClass.init()
}
Here the problem is not able to pass common object which exists in all view controllers. I want to pass apprenderer object like in objective-c.
UIViewControllerto have an additional convenienceinitthat accepts anappRendererTypecan be done withrequiredinitializer but as we can not add arequiredinitializer inextensionso seems impossible by extendingUIViewController. Can you share obj-c code ofinitWithAppRenderwhere it is defined, It might be helpful to find some solution?