Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Swift 2.0 Structs as Data Models Finishing Up Our Model

Generate a random number?

What if i did not want to generate a random count for the array's. What if I only wanted to display the array's in order that they are written?

2 Answers

I made it this way:

I declared a variable at the top

     var elements: Int = 0

and then in the showFunFact function change the value of the variable to show the next array element

    @IBAction func showFunFact() {
        if elements != (factModel.facts.count - 1){
            elements += 1
            funFactLabel.text = factModel.facts[elements]
        }
        else {
            elements = 0
            funFactLabel.text = factModel.facts[elements]
        }
    }

I hope it helps :)

Paul Brazell
Paul Brazell
14,371 Points

you could do a For loop that would loop over each index of the array.

Example:

for index in 0...array.count {
   // Do something
}