I'm trying to generate a random 'workout' with a random number of exercises.
Each exercise needs to have a name (from an array) and a number of reps (a random number which will eventually have 'upper and lower' bounds depending on what type of exercise it is (e.g. up to 10 for push ups, but only 1 for '500m row'. But that can come later! For now, I'm trying to work out how to generate a random number of class instances (I'll then pass these via a segue and put in a tableView, assuming that's possible)
Here's my code, which is just in a playground for now :
import UIKit
let exerciseArray = ["squats", "pushups", "lunges", "jumping jacks"]
class exerciseInWorkout {
var exerciseName : String
var exerciseReps : Int
init(name: String, reps: Int) {
exerciseName = name
exerciseReps = reps
}
}
let randomkey = Int(arc4random_uniform(4))
let numberOfExercisesInWorkout = Int(arc4random_uniform(10))
// Manually creating a new object of exerciseInWorkout with a random exercise and a random number of reps
let exerciseOne = exerciseInWorkout(name:exerciseArray[randomkey], reps:Int(arc4random_uniform((30))))
//print result to make sure it works
print(exerciseOne.exerciseName, exerciseOne.exerciseReps)
//Have some function here which creates a number of class instances based on the "numberOfExercisesInWorkout" constant
If I'm completely on the wrong track here feel free to tell me but I think I'm not far off (hopefully...)