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 trialDavid Fry
412 PointsWhy use a struct and not a class to hold the data?
Why use a struct and not a calls?
4 Answers
Felix Salazar
3,879 PointsNo, if you want to have an object with updated values, you should use a class, because (as the definitions tells) classes are passed by reference, which means: is the same object in all ambits. This link have an example.
Felix Salazar
3,879 PointsThere are some differences between them; You can see them here.
Long story short: Struct are more simple (or less complex, as you want to see them) than Classes. So it's a matter of choice.
David Fry
412 PointsSo because we are going to be updating the value we use a struct because it is passed by copy? So lets say we have multiple locations would you create a new struct for each. IE: var currentLocation = Currently() and then var newLocation = Currently(). How is that different than creating classes?
Felix- What is the best one to use in a productions app?
truemaulik
Courses Plus Student 7,765 PointsThe link shared by Matt has the answer to your question. http://stackoverflow.com/questions/24217586/structure-vs-class-in-swift-language
Matt Groff
2,266 PointsMatt Groff
2,266 PointsHey David,
The course instructor might have specific reasons I'm not aware of, but this might be helpful. http://stackoverflow.com/questions/24217586/structure-vs-class-in-swift-language