I have a ViewController (planExercise) which stores an array of Exercise Objects,
class planExercise: UIViewController {
var exerciseList = [
Exercise(type: "Cardiovascular", name: "Walking", imageName: "walking", calories: 150, time: 30, isComplete: false),
Exercise(type:"Strength",name:"Chair Squats",imageName:"cycling", calories: 200, time: 15, isComplete: false),
Exercise(type: "Flexibility", name: "Seated Toe Touch", imageName: "squats", calories: 100, time: 15, isComplete: false)
]
I have another ViewController (TableViewDetail) which basically adds to the exerciseList array when I click a button, this is what I have so far:
@IBAction func didTapAdd(){
planExercise().exerciseList.append(selectedExercise)
}
I tried to call the planExercise ViewController in the TableViewDetail ViewController and then access the exerciseList array in it and append the selectedExercise into it, however when I run the application, nothing happens to the exerciseList array in the planExercise ViewController and it does not get updated.
Kashyap Hegde Kota is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Because planExercise()
here
planExercise().exerciseList.append(selectedExercise)
is a new instance other than the shown one , you need to use a delegate to pass the actual one which you want to alter it’s array