init
This commit is contained in:
49
Werkout_ios/Views/MainView.swift
Normal file
49
Werkout_ios/Views/MainView.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// ContentView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/13/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import CoreData
|
||||
|
||||
struct MainView: View {
|
||||
@State var workout: Workout?
|
||||
@EnvironmentObject var bridgeModule: BridgeModule
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let workout = workout {
|
||||
let vm = WorkoutDetailViewModel(workout: workout)
|
||||
WorkoutDetailView(viewModel: vm)
|
||||
} else {
|
||||
Text("no workout selected")
|
||||
}
|
||||
}.onAppear{
|
||||
testParse()
|
||||
}
|
||||
}
|
||||
|
||||
func testParse() {
|
||||
if let filepath = Bundle.main.path(forResource: "WorkoutOne", ofType: "json") {
|
||||
do {
|
||||
let data = try Data(NSData(contentsOfFile: filepath))
|
||||
let workout = try JSONDecoder().decode(Workout.self, from: data)
|
||||
bridgeModule.currentWorkout = workout
|
||||
self.workout = workout
|
||||
} catch {
|
||||
print(error)
|
||||
fatalError()
|
||||
}
|
||||
} else {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MainView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user