|
I'm trying to pass along information from ExerciseDetailView to MyWorkouts using @ObservableObject but I get an error under the my preview provider in MyWorkouts that says "Cannot find 'listedWorkouts' in scope. I know my code is kinda messy but please help! MyWorkouts:
|
|
The To fix the error, supply an instance of
You may need to pass arguments to the |
|
Thank you so much for the solution. I have another view named "CreateWorkoutView" and I have a ForEach loop in it. When I set "listedWorkouts" into the ForEach loop, I get an error that says, "Generic struct 'ForEach' requires 'ListedWorkoutsViewModel' conform to 'RandomAccessCollection'" How would I set ListedWorkoutsViewModel to a RandomAccessCollection if it is already an ObservableObject? I tried using a comma and the & sign but I get thrown many errors. CreateWorkoutView:
|
|
I'm assuming this is the code that is causing the error:
The reason you are getting the error is the following declaration in
The What you want to show is the array of workouts inside the view model. The following change should fix the error:
You should consider changing the name of the @ObservedObject to something besides |
SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.