swift go to another view controller code example

Example 1: go to view controller programmatically swift

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "nextView") as! NextViewController
self.present(nextViewController, animated:true, completion:nil)

Example 2: swift go to root view controller

// For Navigation
self.navigationController?.popToRootViewController(animated: true)
// For Presenting modally
self.view.window!.rootViewController?.dismissViewControllerAnimated(false, completion: nil)