|
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 |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.