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 Creating a Data Model Finishing Up Our Model

how can i get the sequence array value, because random can appear twice ?

instead of appearing the random array value, what if i want to appearing the value by the sequence of array variable when i click the button ?

i try to use for in factbook, and change it to func...but it didn't work maybe i think i need the i++ in the viewcontroler, but where i put the function and how to call the function?

Renato Nobre
Renato Nobre
5,805 Points

Can you put your factbook and viewcontrollet file?

maybe its more like ...

var factBook = ["mouse and keyboard", "glass and water", "hungry and burger", "printer and paper"]

func sequenceFact (sequence: String) -> String{

    for i = 0 ; i < factBook.count ; i++ {

    println("\(factBook)")

    }

}

i can see the result in playground, but how to add the i++ in the button so it can appear one by one as a sequance

2 Answers

Renato Nobre
Renato Nobre
5,805 Points

Create a new variable outside the function, like "nextFact" assignt it to 0 and increase that variable inside the function, that way tha variable will be acessible in the view amd will not affect the loop.

i still didnt get it...since im new in this programing course... :p

There is any example or tutorial how to do that in swift project ?