Swift - Structure Memberwise Initializers

Introduction

If the structure has a property that does not have a default value, you cannot use the default initializer syntax.

If you don't initialize the value of row or column to some default value, the following statements will fail:

struct Chess {
     var row:Int        //no default value
     var column:Int     //no default value
}
var c = Chess()      //error

To rectify this, you can use the memberwise initializer to initialize the properties of a structure with certain values when it is created:

var c = Chess ( row:2, column:6 )

Here, when you create an instance of the Chess structure, you set the value for row and column.

Related Topic