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

Why did you specifically use struct? Why not class?

I don't understand why not.

1 Answer

The reason a class is useful is because it's a reference type (allowing data to be uniform across multiple instances) and they can inherit functionality from a previously defined type.

But in this project, I can tell you that Fun Facts will only need one instance of each struct you make, hence there is no need for referencing information. And though there might be a class out there with some of the functionality you need, Pasan wants you to learn how to do it from scratch. Besides, structs don't require you to declare an initializer, so in many case, including this one, simplicity calls for you to chill out and go with structs

There's more information on the difference between value types and reference types in the "Object-Oriented Swift" course.

To add to Joshua's great answer, the key take-away from this exercise is to understand the importance of code-simplicity; that is writing code that is as free from unnecessary or duplicate code as possible to promote the maximum readability.