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 Object-Oriented Swift Complex Data Structures Initializers and Self

Default values vs. init

What is the advantage of using the init method over simply defining a default property value? In this case it would seem simpler to simply define the value.

1 Answer

Gene Bogdanovich
Gene Bogdanovich
14,618 Points

Data structures are made to be flexible. They are basically blueprints. Using init methods allows us to create new instances of a struct with the new values every time. And this is very useful. I recommend you only use default values in very specific situations like when you know that certain property is always the same when you create multiple instances and stick to init methods most of the time.

Thank you