You will need to use the runtime of the object c. Override the init method of your subclass. Create a BaseViewController object using the 'instantiateViewControllerWithIdentifier'. Then set the class for the created object using the objc_setClass method. The following code will go to SubclassViewController.m.
- (instancetype)init { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"main" bundle:[NSBundle mainBundle]]; UIViewController *baseClassViewController = [storyboard instantiateViewControllerWithIdentifier:@"baseClassIdentifier"]; object_setClass(baseClassViewController, [SubclassViewController class]); return (SubclassViewController *)baseClassViewController; }
After that, you can simply create the SubclassViewController object using the simple [[SubclassViewController alloc] init].
source share