Thursday, February 21, 2019

Passing data to another viewcontroller Swift

We will pass a string to class second.
let text = "This is example text"
In ViewController.swift, function for button to open second class like this.
func next(sender: UIButton){
       let vc = second()
     vc.passingtext = text
        self.presentViewController(vc, animated: true, completion: nil)
    }
Ignore red mark error.
Go to class second.swift, copy to above override
var passingtext = " "
Add to viewDidLoad
la.text = passingtext
Run to see result.

We can pass text, number, array or any data types.


No comments:

Post a Comment