How to pass data between UIViewController (Swift)

February 05, 2019

One of the simplest tasks in iOS is being able to pass data between View Controllers. The idea is very simple and easy to implement but not be exactly clear especially if you are use to Android.

Let's see how you do it: ViewController2.swift

public class ViewController2: UIViewController {
    public let parameter: String?
}
public class ViewController: UIViewController {
    ... 
    let vc = ViewController2()
    vc.parameter = "Pass this parameter"
    present(vc, animated: true, completion: nil)
    ...
}