First make a class/struct of Workout with a flag
struct Workout {
let name: String
let isComplete: Bool
}
Make a sample Data Model
var workouts = [
Workout(name: "Squats", isComplete: false),
Workout(name: "Burpees", isComplete: false),
Workout(name: "Crunches", isComplete: true),
Workout(name: "Push Ups", isComplete: false),
Workout(name: "Jumping Jacks", isComplete: true),
Workout(name: "High Knees", isComplete: false),
Workout(name: "Lunges", isComplete: false),
Workout(name: "Plank", isComplete: false),
Workout(name: "Sechigh Knees", isComplete: false),
Workout(name: "Tricep Dips", isComplete: false),
Workout(name: "Mountain Climbers", isComplete: true),
Workout(name: "Wall Sit", isComplete: true),
Workout(name: "Squats 2", isComplete: false),
Workout(name: "Burpees 2", isComplete: false),
Workout(name: "Crunches 2", isComplete: true),
Workout(name: "Push Ups 2", isComplete: false),
Workout(name: "Jumping Jacks 2", isComplete: false),
Workout(name: "High Knees 2", isComplete: false),
Workout(name: "Lunges 2", isComplete: false),
Workout(name: "Plank 2", isComplete: false),
Workout(name: "Sechigh Knees 2", isComplete: true),
Workout(name: "Tricep Dips 2", isComplete: false),
Workout(name: "Mountain Climbers 2", isComplete: false),
Workout(name: "Wall Sit 2", isComplete: false),
]
Make a custom UITableViewCell with a Workout type variable
class CustomCell: UITableViewCell {
var workout: Workout? {
didSet {
guard let workout = workout else { return }
self.textLabel?.text = workout.name
if workout.isComplete {
self.accessoryType = .checkmark
}
else {
self.accessoryType = .none
}
}
}
}
Then in tableView:cellForRowAtIndexPath:
method pass the variable
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell
cell.workout = workouts[indexPath.row]
return cell
}