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

Once non repeating struct ends the app stops working, what do i need to do to keep the app working?

Hello there i have this code for the Fun Facts App but i made some changes into the code to dispay other facts i have 19 onc i finished the count the app stop working, what can i do to continue displaying fact.

struct FactBook {

    // This will hold the random index

    var previousRandomIndex = 0
    let factsArray = [
        "Los Pandas son muy bonitos.",
        "Pandis, están muy contentos de que eres su papi.",
        "Lo mejor del mundo panda es ser peludos.",
        "El 21 de Marzo es el.",
        "Toma menos de 5 jijiji.",
        "Los pandas, hacen muy buen equipo.",
        "Vamos a ser pandas famosos.",
        "A Panda Baby Bear le gusta ir a Cancún.",
        "Panda .",
        "Es saludable darle masajes a patita de Panda Baby Bear.",
        "Estudios demuestran que los pandas son muy felices.",
        "El cariño es la forma más sana de consentir a un panda.",
        "Un panda prefiere más veces un bombón que una paleta.",
        "Se dice que los pandas se acurrucan muy fácil.",
        "Si un panda te abraza, Felicidades eres muy afortunado.",
        "El 27 de  Bear.",
        "Los Pandas gustán.",
        "A veces extrañamos Coffee Bean.",
        "Alegría es compartir una bonita tarde acurrucados.",



    ]

    func randomFact() -> String {
        var unsignedArrayCount = UInt32(factsArray.count)
        var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
        var randomNumber = Int(unsignedRandomNumber)

        do {
            randomNumber = Int(unsignedRandomNumber)

        } while randomNumber == previousRandomIndex


        return factsArray[randomNumber]
    }

}

Thanks for any help

1 Answer

You wrote an extra comma at the end of factsArray. Maybe that's what's causing you trouble.

Saludos! :)