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 Creating a Data Collection

how to make my APP change every time when i press next? :\

class ViewController: UIViewController {
    @IBOutlet weak var funFactLable: UILabel!
    let FunFacts = ["never give up" ,
        "the better we get to get better tha faster we get better" ,
        "life will never stop for any one" ]

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func showFunFact() {

        funFactLable.text = FunFacts[1]

    }
}

this is my code and when i run it it shows me a label with text " Fun Fact " and when i press next i shows me the element that i specified it's not like Mr.Pasan Premaratne :\

2 Answers

Hi there,

That will only ever show the second element in the array as you have hard-coded FunFacts[1]. In the course, either already or in ones you've not seen yet, you will build a random number generator to replace the [1] with a random number so that all your array elements have the chance to be displayed.

Or, is your label's initial text staying there, something like "An interesting fact goes here", rather than "the better we get ..." etc.? If this is the problem, you'll need to make sure that your outlet is working. Try going through this video again after deleting your existing outlets, if there are any. That should connect your label to your code and allow you to control it.

Steve.

Steve Hunter, I removed my post, I was jumping ahead :) thanks for catching that.

NOUR A ALGHAMDI Let's us know if you still need help after watching that video.

No problem! Your post was accurate, just a little early! :-)

thank you both Aaron Ackerman and Steve Hunter that helped me :)

No problem - glad to help. Shout if you get stuck!