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 Structs As Data Models Structs or Classes

Structs or Classes - Building a Simple iPhone App with Swift

When Pasan creates the iPhone app Fun Facts it appears to me (Unless I am missing something) that the app can only show two facts total out of all the available facts in the array. Is this the case (And he is doing it to keep it simple) or am I doing something wrong with my code? - For example Using factProvider.facts[1] is only ever going to give the second fact in the array, so it will never really change.

class ViewController: UIViewController { @IBOutlet weak var factsGoHere: UILabel!

let factProvider = FactProvider()

override func viewDidLoad() {
    super.viewDidLoad()

    factsGoHere.text = factProvider.facts[0]

}

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


@IBAction func newFact(_ sender: Any) {

    factsGoHere.text = factProvider.facts[1]

}

}

1 Answer

Stuart Wright
Stuart Wright
41,118 Points

You are correct, but don't worry about it - he edits this logic in a later video. At this stage he's just showing you how you can make data from your model visible in the view.