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
Mark Wells
7,313 Points"Memberwise"
Why do we call an initializer "memberwise"? What does that mean, and are there other kinds of initializer?
3 Answers
Steven Deutsch
21,046 PointsHey Mark Wells,
I believe it's because a structure is a value type as opposed to a reference type (classes). This means that its values are copied when instances of the structure are passed around in code. Memberwise assignment is copying one object to another object. So it makes sense to call this a memberwise initializer. I'm by no means an expert on the meaning behind this, so sorry for the light explanation.
Steven Deutsch
21,046 PointsHey Mark Wells,
The term "memberwise initializer" is used to refer to the initializer that is automatically provided for you while using Structures. This means, when you create your structs you don't need to create initializers for them to create instances in your code. Swift will provide the initializer automatically. However, you can still define your own initializer if you want to execute some custom initialization. This is not the same for classes. When creating a class, you do not receive an automatic memberwise initializer. Every class needs to be provided with an initializer.
Good Luck
Mark Wells
7,313 PointsThank you for the reply. To clarify my question, why do we use the word "memberwise" to describe this situation? I am trying to understand what it describes, semantically, that is not also true of any other initializer.
Mark Wells
7,313 PointsMark Wells
7,313 PointsThank you, that makes a lot of sense! I appreciate your quick and clear replies :)