From c77ed03ca2a190f224541c07a057081a1db4d3fe Mon Sep 17 00:00:00 2001 From: Trey t Date: Wed, 21 Jun 2023 20:30:07 -0500 Subject: [PATCH] WIP --- .../Preview Content/PreviewWorkout.swift | 60 +++++++++++++++++++ Werkout_ios/Views/AddExerciseView.swift | 51 +--------------- Werkout_ios/Views/AllWorkoutsView.swift | 15 +---- 3 files changed, 62 insertions(+), 64 deletions(-) diff --git a/Werkout_ios/Preview Content/PreviewWorkout.swift b/Werkout_ios/Preview Content/PreviewWorkout.swift index 39e835b..c5d0813 100644 --- a/Werkout_ios/Preview Content/PreviewWorkout.swift +++ b/Werkout_ios/Preview Content/PreviewWorkout.swift @@ -14,4 +14,64 @@ class PreviewWorkout { let workout = try! JSONDecoder().decode(Workout.self, from: data) return workout } + + class func allWorkouts() -> [Workout] { + if let filepath = Bundle.main.path(forResource: "AllWorkouts", ofType: "json") { + do { + let data = try Data(NSData(contentsOfFile: filepath)) + let workout = try JSONDecoder().decode([Workout].self, from: data) + return workout + } catch { + print(error) + fatalError() + } + } else { + fatalError() + } + } + + class func parseExercises() -> [ExerciseExercise] { + if let filepath = Bundle.main.path(forResource: "Exercises", ofType: "json") { + do { + let data = try Data(NSData(contentsOfFile: filepath)) + let exercises = try JSONDecoder().decode([ExerciseExercise].self, from: data) + return exercises + } catch { + print(error) + fatalError() + } + } else { + fatalError() + } + } + + class func parseEquipment() -> [Equipment] { + if let filepath = Bundle.main.path(forResource: "Equipment", ofType: "json") { + do { + let data = try Data(NSData(contentsOfFile: filepath)) + let equipment = try JSONDecoder().decode([Equipment].self, from: data) + return equipment + } catch { + print(error) + fatalError() + } + } else { + fatalError() + } + } + + class func parseMuscle() -> [Muscle] { + if let filepath = Bundle.main.path(forResource: "AllMuscles", ofType: "json") { + do { + let data = try Data(NSData(contentsOfFile: filepath)) + let muscles = try JSONDecoder().decode([Muscle].self, from: data) + return muscles + } catch { + print(error) + fatalError() + } + } else { + fatalError() + } + } } diff --git a/Werkout_ios/Views/AddExerciseView.swift b/Werkout_ios/Views/AddExerciseView.swift index c1e3f40..572065f 100644 --- a/Werkout_ios/Views/AddExerciseView.swift +++ b/Werkout_ios/Views/AddExerciseView.swift @@ -198,54 +198,5 @@ struct AddExerciseView: View { return hasCorrectMuscles && hasCorrectEquipment } }) - } - -// func parseExercises() { -// if let filepath = Bundle.main.path(forResource: "Exercises", ofType: "json") { -// do { -// let data = try Data(NSData(contentsOfFile: filepath)) -// let workout = try JSONDecoder().decode([ExerciseExercise].self, from: data) -// self.filteredExercises.append(contentsOf: workout) -// self.exercises = workout -// } catch { -// print(error) -// fatalError() -// } -// } else { -// fatalError() -// } -// } -// -// func parseEquipment() { -// if let filepath = Bundle.main.path(forResource: "Equipment", ofType: "json") { -// do { -// let data = try Data(NSData(contentsOfFile: filepath)) -// let workout = try JSONDecoder().decode([Equipment].self, from: data) -// self.equipment = workout -// self.selectedEquipment.append(contentsOf: workout) -// } catch { -// print(error) -// fatalError() -// } -// } else { -// fatalError() -// } -// } -// -// func parseMuscle() { -// if let filepath = Bundle.main.path(forResource: "AllMuscles", ofType: "json") { -// do { -// let data = try Data(NSData(contentsOfFile: filepath)) -// let workout = try JSONDecoder().decode([Muscle].self, from: data) -// self.muscles = workout -// self.selectedMuscles.append(contentsOf: workout) -// } catch { -// print(error) -// fatalError() -// } -// } else { -// fatalError() -// } -// } - + } } diff --git a/Werkout_ios/Views/AllWorkoutsView.swift b/Werkout_ios/Views/AllWorkoutsView.swift index 3aaeae4..eb45f9a 100644 --- a/Werkout_ios/Views/AllWorkoutsView.swift +++ b/Werkout_ios/Views/AllWorkoutsView.swift @@ -68,18 +68,5 @@ struct AllWorkoutsView: View { } } - func testParse() { - if let filepath = Bundle.main.path(forResource: "AllWorkouts", ofType: "json") { - do { - let data = try Data(NSData(contentsOfFile: filepath)) - let workout = try JSONDecoder().decode([Workout].self, from: data) - self.workouts = workout - } catch { - print(error) - fatalError() - } - } else { - fatalError() - } - } + }