How to initialize classes and structures using initializer and default property values?

Classes and Structures in Swift must initialize all of their stored properties before an instance of class or structure is ready for use. This can be done using initializers or assigning default initial values to the stored properties.


Initializers are called to create new instance of particular type. They are like instance method without parameter name written using init keyword.

Using Default Property Values

We can also initialize classes and structures by assigning default values to their stored properties. This can be done by specifying default property value as a part of property’s declaration.

Leave a Reply