BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

Value has no member .image from struct?

Forums > SwiftUI

Fairly new to Swift and SwiftUI, so I'm probably not understanding something correctly here, but on line 16 where I have a ZStack, I try to pass in workouts.image and I get thrown an error that says, "Value of type '[MyWorkoutsWorkout]' has no member 'image'."

I have two files that would affect it. Here they are:

MyWorkoutsCards: https://pastebin.com/da6qBVYY MainView: https://pastebin.com/HGde5Fd9

Thanks!

   

Michaela wonders how to pass data to a Struct:

Fairly new to Swift and SwiftUI, so I'm probably not understanding something correctly here, but on line 16 where I have a ZStack, I try to pass in workouts.image

First, I don't see where on line 16 you're passing in an image. But, that issue aside, you certainly aren't understanding how to pass data to a Struct. This site has several tutorials, even a fantastic 100 Days of SwiftUI program!

Many of these tutorials cover the concepts of how to properly initialize a view Struct. @twoStraws does a GREAT job teaching these fundamentals.

struct MyWorkoutsCards: View {

    let workouts = workoutsData  // <-- This is not the way to provide an array of data to a Struct

    // ... snip ...
}

// Data array created Elsewhere......
let workoutsData = [ MyWorkoutsWorkout(day: "Monday", bodyPart: "Chest", image: "push-ups", routine: ["Warmup", "Flat Dumbbell Bench Press", "High Cable Flys", "Inclined Dumbbell Bench Press", "Cooldown"]),

1      

@Obelix I admire your in dept and thorough explanations you provide beginners with, time and again! chapeau!

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.