I think michaela is having a data modeling problem, not a Swift coding problem.
I am having trouble putting my individual workouts
into the variable routine array of type [workouts].
This is the error I get currently: "
Cannot convert value of type 'workouts.DumbbellBenchPress.Type' to expected element type 'Array<workouts>.ArrayLiteralElement'
Your code:
// Two data types, but they hold identical data.
struct DumbbellBenchPress {
let name = "Dumbbell Bench Press"
let image = "push-ups"
let video = ""
let description = "The Dumbbell Bench Press is similar ... snip ..."
}
struct Pushups {
let name = "Pushups"
let image = "push-ups"
let video = ""
let description = "Pushups are one of the best dynamic exerc ... snip...."
}
You may want to rethink your data models. In this case, both structs have the same content, but have different titles. To Swift you've created TWO different types. These cannot be put into a single array. Because arrays want to store the same types.
Instead, consider creating a struct named Exercise
and one of the structs properties is focus
. Example:
struct Exercise {
var focus = "Pectorals" // <-- consider making this an enum !
var name = "Pushups"
var image = "pushups-elbows-in"
var video: String? = nil // you may not have a video
var description = "Also knows as =Let Downs="
}
Then you can put any struct
of type Exercise
into an array named workout
of type [Exercise]
.
let chestWorkout: [Exercise] = [] // start with empty array. but it can only hold exercises.
let letDowns = Exercise(focus: "Pectorals", name: "Let Downs") // create new exercise
let pushUps = Exercise(focus: "Pectorals", name: "Push Ups") // create another exercise
chestWorkout.append( letDowns )
chectWorkout.append( pushUps )