jeudi 30 mars 2017

Choose random data from an Array in Swift

I would like to create a new Array of 3 random values pulled from this list to be used in two other view controllers. Not sure how to assign the Array so those values are accessible.

class WorkoutDataSource {
var allWorkouts:[Workout]

init() {
    allWorkouts = []
    let bh1 = Workout(title: "Figure 8s - Clockwise", workoutText: "Clockwise around each leg.", color:  UIColor.flatNavyBlueColorDark())
    allWorkouts.append(bh1)
    let bh2 = Workout(title: "Figure 8s - Counter Clockwise", workoutText: "Counter Clockwise around each leg.", color:  UIColor.flatNavyBlue())
    allWorkouts.append(bh2)
    let bh3 = Workout(title: "Dribble Left Handed", workoutText: "Low and Powerfull.", color:  UIColor.flatTealColorDark())
    allWorkouts.append(bh3)
    let bh4 = Workout(title: "Dribble Right Handed", workoutText: "Low and powerfull", color:  UIColor.flatTeal())
    allWorkouts.append(bh4)
    let bh5 = Workout(title: "Around Both Feet", workoutText: "With feet together, circles around ankles-waist-head, work up & down, the full length of body.", color:  UIColor.flatSkyBlueColorDark())
    allWorkouts.append(bh5)
    let bh6 = Workout(title: "Spider Dribble", workoutText: "feet apart, 1 dribble with each hand in front, then 1 dribble with each hand in back. ", color:  UIColor.flatSkyBlue())
    allWorkouts.append(bh6)
    let bh7 = Workout(title: "Helicopter", workoutText: "1 hand in front, 1 hand in back – move your hands from front to back while catching the ball between your legs.", color:  UIColor.flatGreenColorDark())
    allWorkouts.append(bh7)
    let bh8 = Workout(title: "Scissors - Legs Not Moving", workoutText: "One leg forward and one leg back. Dribble between your legs low and fast.", color:  UIColor.flatGreen())
    allWorkouts.append(bh8)
    let bh9 = Workout(title: "Behind the Back", workoutText: ".",color:  UIColor.flatGray())
    allWorkouts.append(bh9)
    let bh10 = Workout(title: "Fingertip Squeeze", workoutText: ".",color:  UIColor.flatPink())
    allWorkouts.append(bh10)
}


func getWorkOuts() -> [Workout]{

return allWorkouts
}

}

Thank you




Aucun commentaire:

Enregistrer un commentaire