UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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!

2      

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"]),

3      

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

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

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.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.