[swift] How can I switch views programmatically in a view controller? (Xcode, iPhone)

Have been struggling with this for a while, and can never seem to get a direct answer.

Any help is appreciated!

This question is related to swift uiviewcontroller swift3 storyboard

The answer is

If you're in a Navigation Controller:

ViewController *viewController = [[ViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];

or if you just want to present a new view:

ViewController *viewController = [[ViewController alloc] init];    
[self presentViewController:viewController animated:YES completion:nil];

Similar questions with swift tag:

Similar questions with uiviewcontroller tag:

Similar questions with swift3 tag:

Similar questions with storyboard tag: