Return from initializer without initializing all stored properties error in Swift initialization

This error may occur due to the fact that a constant is assigned a optional type and not provided with explicit value. Constants can be assigned with a value only once. So when we declare a stored property inside a type as constant with optional type, Swift compiler wants us to assign a explicit value during initialization as the value cannot be overwritten in future. We can either provide a optional constant with nil  or provide any default value. Once it is assigned with a explicit value we cannot change the value for the optional constant after a instance is initialised. This is not true for variable type as it is automatically assigned with nil value during initialization and we can change that value after initialization.

 

 

 

Advertisements

Leave a Reply