0

I have just started to learn Swift and I'm struggling with a few problems, one of them being this:

I have the following app: ViewController1 -> ViewController2 -> ViewController3.

How can I pass a value from ViewController1 to ViewController3?

I was thinking on creating a static variable (see in the code, var CNP) in the class corresponding to ViewController1 and access it by creating an instance of this class in ViewController 3, but unfortunately I can't manage to do it.

Here is my ViewController1:

class PageCNP: UIViewController {

@IBOutlet weak var labelCNP: UITextField!
@IBOutlet weak var labelDoB: UITextField!


internal var CNP: String = labelCNP.txt //why can't I do that?

override func viewDidLoad() {
     //some code here
}

override func didReceiveMemoryWarning() {
    //some code here
}


func extractYearOfBirth() -> NSString
{
    //some code here

}


@IBAction func verifyCNP(sender: AnyObject) {

  //some code here


}

In ViewController3 I want to do this (if it's correct):

    @IBOutlet weak var cnpClient: UILabel!    

    override func viewDidLoad() {
    super.viewDidLoad()
    var x = PageCNP()
    cnpClient.text = x.CNP
}
akashivskyy
  • 40,844
  • 15
  • 103
  • 113
Bogdan R
  • 51
  • 7

0 Answers0