Swift presentViewController Swift presentViewController swift swift

Swift presentViewController


Try this:

let vc = ViewController() //change this to your class nameself.presentViewController(vc, animated: true, completion: nil)

With Swift3:

self.present(vc, animated: true, completion: nil)


For those getting blank/black screens this code worked for me.

    let vc = self.storyboard?.instantiateViewController(withIdentifier: myVCID) as! myVCName    self.present(vc, animated: true, completion: nil)

To set the "Identifier" to your VC just go to identity inspector for the VC in the storyboard. Set the 'Storyboard ID' to what ever you want to identifier to be. Look at the image below for reference.


For reference, because this question is one of the first Google result.

Breaking change in Swift 3:

The method presentViewController is replaced by the method present.

You can use it like the old one:

self.present(viewControllerToPresent, animated: true, completion: nil)

Example to open the camera:

let imagePicker = UIImagePickerController()imagePicker.delegate = selfimagePicker.sourceType = UIImagePickerControllerSourceType.cameraimagePicker.allowsEditing = falseself.present(imagePicker, animated: true, completion: nil)