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 trialRyan Jin
15,337 PointsDifference between Struct and Class
Is all the difference between Struct and Class is that a copy of an instance of class is the same as the original instance, and in struct, it creates a new object?
1 Answer
James Marchant
6,963 PointsA class is passed by reference and a struct is passed by value. So yes, the struct is copied to the new value where as the class is just passing the reference to the object over to the new value, So that value a and value b both 'point' or reference the same object.
Here is a great thread that helped me understand it better on stackOverflow: http://stackoverflow.com/questions/24217586/structure-vs-class-in-swift-language
Ryan Jin
15,337 PointsRyan Jin
15,337 PointsIs that the only difference?