I have two ways to navigate to make CreateWorkout View, one is the user creating a new workout by tapping on a button in the toolbar:
.toolbar {
NavigationLink() {
AddWorkoutView()
} label : {
Image(systemName: "plus.circle")
.resizable()
.frame(width: 24, height: 24)
}
}
The other is a User clicking on an existing workout in a list to edit it further:
List(workouts) { workout in
NavigationLink {
AddWorkoutView(workout: workout)
} label: {
VStack {
Text(workout.name ?? "No name")
}
}
}
how do I differentiate in my Create Workout View between editing an existing workout and creating a new one? so far I only have code for creating a new one and that is a create a temporary workout object that I will write to swiftData when the user presses the save button later but until then they are free to edit it:
struct AddWorkoutView: View {
@Environment(.modelContext) var modelContext
@State private var workoutName: String = ""
@State private var showExercieSheet = false
@State private var workoutStartTime = Date.now
@State private var workoutEndTime = Date.now
//I will build this temporary workout object then write it to the db
@State private var workout: Workout = Workout(id: UUID())
I need a way of knowing if a workout has been passed or not so I can use that rather than creating a brand new one, is there any way to do this in SwiftData?