Hi!
I have been working on a workout app. I have a model "Workout" which holds a list of Exercises (EInfo). There can be multiple workouts stored in an app. I am currently trying to create an on move function for a list that shows the exercises in a workout. However, just using a simple swap function does not seem to work. Is there something I am missing? I cant seem to find much information about this
@Model
class Workout {
@Attribute(.unique) var id: UUID
var date: Date
var name : String
var exercises: [EInfo]
var isFinished: Bool
init(id: UUID = UUID(), date: Date = Date.now, name: String = "New Workout", exercises: [EInfo] = [], isFinished: Bool = false) {
self.id = id
self.date = date
self.name = name
self.exercises = exercises
self.isFinished = isFinished
}
}
@Model
class EInfo {
@Attribute(.unique) var id: UUID
var name: String
var sets: [ESet]
var orderIndex: Int
init(id: UUID = UUID(), name: String = "", sets: [ESet] = [ESet()]) {
self.id = id
self.name = name
self.sets = sets
self.orderIndex = 0
}
func isCompleted()->Bool{
return sets.allSatisfy { $0.done } && sets.count > 0
}
//need help here
List{
ForEach(workout.exercises) { exercise in
HStack{
ExerciseListView(workout: workout, exerciseInfo: exercise, isEditing: $isEditing)
.frame(width: width, height: 40)
.listRowSeparator(.hidden)
}.listRowBackground(Capsule().fill(Color.blue).stroke(Color.black, lineWidth: 2))
}
.onMove {from, to in
}
}
}