Navigate from one controller to another controller in swift

Redirect from one UIViewController to another UIViewController

let VCCart = CartViewController(nibName: "CartViewController", bundle: nil)
self.navigationController?.pushViewController(VCCart, animated: true)

Above code is used when you are using navigation controller.

let VCCart = CartViewController(nibName: "CartViewController", bundle: nil)
self.present(VCCart, animated: true, completion: nil)

Above code is used when you are not using navigation controller.

Back from one UIViewController to another UIViewController

self.navigationController?.popViewController(animated: true)

Above code is used when you are using navigation controller.

self.dismiss(animated: true, completion: nil)

Above code is used when you are not using navigation controller.