I am trying to create an instance of a "budget" class when I click a button that for now just has the information on the inputed gross income. When this button is pressed I want to create an instance of this budget class and then use this instance in a new view controller that appears to display data. What is the best way to do this? Should I be doing this a different way?
Right now I have a budget class as shown below:
import Foundation
class Budget {
private var _grossIncome: Int!
var grossIncome: Int {
return _grossIncome
}
init(grossIncome: Int) {
self._grossIncome = grossIncome
}
}
And a view controller with the button to be pressed here:
import UIKit
class CreateNewBudgetVC: UIViewController {
@IBOutlet weak var grossIncomeVal: UITextField!
@IBOutlet weak var locationVal: UITextField!
@IBOutlet weak var federalExptVal: UITextField!
@IBOutlet weak var stateExptVal: UITextField!
@IBOutlet weak var deductionsList: UITableView!
@IBAction func cancelPressed(_ sender: Any) {
performSegue(withIdentifier: "CancelSegue", sender: self)
}
@IBAction func generateBudgetPressed(_ sender: Any) {
performSegue(withIdentifier: "GenerateSegue", sender: self)
let budget = Budget(grossIncome: Int(grossIncomeVal.text!)!)
}
}
So, how do I make it so when the "genereateBudgetPressed" method is called on button click it creates a new instance of the budget class with the inputed gross income and I can use this information to display things on a new view controller? Is there a better way to be doing this whole process?
_grossIncometo be anInt!. It can just be anInt