How to initialize structures in Swift?

Structures in Swift must initialize all of their stored properties before an instance of structure is ready for use. This can be done using initializers or assigning default initial values to the stored properties. Structure types automatically receive a member-wise initializer if they don’t have their own custom initializers(More on this in later posts).


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 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