Swift - Adding enum to structure


The following code creates a new enumeration called StoneColor and adds a color property to the Chess structure:

enum StoneColor:String {
     case Black = "Black"
     case White = "White"

struct Chess {
    var row:Int              //0...7
    var column:Int           //0...7
    var color:StoneColor

The color property is an enumeration of type StoneColor.

To create an instance of the Chess structure, use the memberwise initializer:

var stone1 = Chess ( row:2, column:6, color:StoneColor.Black )

Related Topic