What would be the best approach to implementing a way to show the goals and then have each goal display a view just showing their information? Would it be best if I just created a list of navigation views so that each category had its own info? I also think there’s a huge chance that I’m just really oversimplifying this entire part of code. I bolded the speicifc issue i need help with. These are the possible solutions Im thinking about, a text field where the user picks from an outputted list of goals (they have to type the answer), Or maybe a list of navigation views (Im going to try this one next)
Just looking for insight and advice on what would be the easiest approach to this, using the previous code I have, the enum way of storing data.
I tried using AI and my online resources but they seem to overcomplicate it
`
import SwiftUI
// Define an enum for exercise types
enum ExerciseType: , CaseIterable {
case abs, biceps, triceps, weightloss, thighs, endurance, balance, swimming
}
// Define a struct for exercise data
struct ExerciseData {
let name: String
let description: String
let exercises: [String]
let image: String
}
// Define ExerciseListView
struct ExerciseListView: View {
// Define your exercises data
let exercises: [ExerciseType: ExerciseData] = [
.abs: ExerciseData(
name: "Abs",
description: "Engaging in abdominal exercises enhances core strength, promoting better posture and stability while reducing the risk of back pain.",
exercises: ["Crunches", "Leg Raises", "Russian twists", "Plank", "Bicycle crunches"],
image: ""
),
.biceps: ExerciseData(
name: "Biceps",
description: "Strengthening your biceps improves upper body power, stability, and overall arm functionality.",
exercises: ["Bicep curls", "Hammer curls", "Preacher curls", "Concentration curls", "Incline dumbbell curls"],
image: ""
),
.triceps: ExerciseData(
name: "Triceps",
description: "Working on triceps enhances arm strength, aids in pushing movements, and contributes to overall arm definition and balance.",
exercises: ["Tricep pushdowns", "Overhead dumbbell extensions", "Skull crushers", "Close grip bench press", "Tricep dips"],
image: ""
),
.weightloss: ExerciseData(
name: "WeightLoss",
description: "A combination of cardio and strength training exercises to help you achieve your weight loss goals, to help eliminate chances of obesity and diabetes",
exercises: ["Jogging", "Cycling", "Swimming", "High-intensity interval training", "Burpees"],
image: ""
),
.thighs: ExerciseData(
name: "Thighs",
description: "Strengthening your thighs improves overall leg strength, stability, and balance. This also helps those who are looking to gain more lower body strength.",
exercises: ["Squats", "Leg press", "Lunges", "Leg curls", "Leg extensions"],
image: ""
),
.endurance: ExerciseData(
name: "Endurance",
description: "Improving your endurance through cardio exercises enhances your overall fitness and well-being.",
exercises: ["Long-distance running", "Swimming", "Cycling", "Rowing", "Jumping Rope"],
image: ""
),
.balance: ExerciseData(
name: "Balance",
description: "Improving your balance through exercises enhances your overall coordination and stability.",
exercises: ["Beam walk", "Dance", "Squats", "Butterfly", "Jumping Jacks"],
image: ""
),
.swimming: ExerciseData(
name: "Swimming",
description: "Improving your endurance through cardio exercises enhances your overall fitness and well-being.",
exercises: ["Freestyle", "Backstroke", "Breaststroke", "Butterfly Stroke", "Dry Land"],
image: ""
)
]
var body: some View {
// part that i need help with
}
// When a user selects an exercise type:
func didSelectExerciseType(_ type: ExerciseType) {
guard let exerciseData = exercises[type] else { return }
// Display the exercise data, e.g., in a detail view controller
print("Selected exercise: (exerciseData.name)")
print("Description: (exerciseData.description)")
print("Exercises: (exerciseData.exercises)")
print("Image: (exerciseData.image)")
}
}
// Preview provider
struct ExerciseListView_Previews: PreviewProvider {
static var previews: some View {
ExerciseListView()
}
}
`