|
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 |
SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
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.