I have two view controllers and I want to pass the number from one view controller to the next using a button. But after I pass that number, I want that number to add to the next one so it keeps adding everytime the button is pressed. So far it works just by passing the string but I can't figure out how to convert that string to a number and then add that number. The string is stored in Firebase because I want to be able to change that number being added.
Here is my code:
View Controller with Button
@IBAction func verifyButton(_ sender: Any) {
print("Button Clicked")
let ref3 = Database.database().reference()
ref3.child("Pay/Ad001").queryOrderedByKey().observeSingleEvent(of: .value, with: { (snapshot) in
})
let myVC = storyboard?.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController
myVC.stringPassed = LabelOne.text!
navigationController?.pushViewController(myVC, animated: true)
UserDefaults.standard.setValue(LabelOne.text!, forKey: "stringPassed")
}
2nd View Controller with numbers I want being added:
override func viewDidLoad() {
super.viewDidLoad()
//pass number here and add
totalEarned.text = stringPassed
totalEarned!.text=UserDefaults.standard.string(forKey: "stringPassed")