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 Refactoring Into a Model

Cyrus Hung
Cyrus Hung
2,571 Points

Why do we need to create a 'Struct" to store the "Array"? Is the "Array" good enough to do the job?

Why do we need to create a 'Struct" to store the "Array"? Is the "Array" good enough to do the job?

1 Answer

Logan R
Logan R
22,989 Points

The reason he moved the array to a struct was to better organize the code and make the code look cleaner. The array worked there because it only had a few facts, but what if we wanted to add 100 facts? It would look very messy and hard to deal with. A struct helps solves this problem by moving the array to an independent file. This also allows us to add functions to the struct if we want to perform certain operations on the data, like randomly selecting an element.