I am trying to get data from a different screen but for some reason, the variable does not update. here is the code so far
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let viewController: UIViewController = UIViewController()
switch (indexPath.row) {
case 0:
print("hello")
let vc = AddViewController()
vc.chosenDaily = true
dismiss(animated: true, completion: nil)
here I created a tableView and once the user clicks on the first index of my tableView I want to set a boolean variable to true and return to another screen. I declared this boolean variable on the other screen here.
var chosenDaily:Bool = false
on the same screen, I have a save button and want to print the result.
@IBAction func didTapSaveButton() {
if chosenDaily == true {
print("it's true")
} else if chosenDaily == false {
print("it's false")
}
}
but for some reason, the code doesn't update and returns false instead of true. can anyone help? thanks for any help that i get