0

I am trying to take these variables from one of my view controller's swift file:

 //global let choice1Box1 = drivingGear[chooseDrivingGear.selectedRow(inComponent: 0)] let choice2Box1 = drivingGear[chooseDrivenGear1.selectedRow(inComponent: 0)] 

This is whats being done to the variables in the original class:

@IBAction func showResultBox1(_ sender: Any) { let choice1Box1 = self.drivingGear[self.chooseDrivingGear.selectedRow(inComponent: 0)] let choice2Box1 = self.drivingGear[self.chooseDrivenGear1.selectedRow(inComponent: 0)] if let intVal1 = Double(choice1Box1), let intVal2 = Double(choice2Box1) { result = intVal2 / intVal1 let newLabel = String(result) resultBox1.setTitle(newLabel, for: .normal) } } 
2
  • You can pass data from one VC to another VC, by using Delegate and also you can use prepare(forSegue:) method. matteomanferdini.com/… Commented Apr 19, 2018 at 2:02
  • Have added the answer in it, Please look into that. Commented Apr 20, 2018 at 12:14

1 Answer 1

1

Just do like this:

Once you have picked the value from the pickerView. Pass it like this.

For Eg. You need to pass a String to next VC:

In SecondVC: Declare a value at top like this:

var strFromPreviousVC:String = String() 

In First VC: Send the Value like this:

let objSecondVC = self.storyboard?.instantiateViewController(withIdentifier: "secondVC") as! SecondVC objSecondVC.strFromPreviousVC = "your selected String here" self.navigationController?.pushViewController(objSecondVC, animated: true) 

And yes its done, it will be passed to SecondVc and you can use the value like print(strFromPreviousVC) in SecondVc

Hope it helps.

Sign up to request clarification or add additional context in comments.

4 Comments

In addition you can use delegate
@Brkr I agree with you, but delegates would be troublesome for Newbie's.
You are absolutely right. i gave positive vote for your answer.
Really appreciated that buddy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.