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

Michael Brown
Michael Brown
12,406 Points

In the Tower & Enemy game made with Swift, what's the overarching purpose of making "Enemy" a class and not a struct?

I'm understanding the difference between the two different data types, but specifically in this project, I'm curious as to why didn't we just create all structs with "Tower", "Enemy", and "Point", or vice versa. Why didn't we just make them all classes?

I would like to assume that the reason why we made "Tower" and "Enemy" classes was because we planned on creating subclasses such as "SuperEnemy" to customize and inherit "Enemy" class' properties. However, I'd like to sure and maybe there are more reasons as well.

Thanks in advance and Happy learning for all!

1 Answer

Addison Francisco
Addison Francisco
9,561 Points

Your assumption is correct. Since you can’t subclass a struct, you need to use a class for this example

Michael Brown
Michael Brown
12,406 Points

Thanks Addison. Perhaps I should've waited until I got to the "Structs vs Classes" video before I asked my question. πŸ˜