My course states the following regarding enums:
The initialization of an enum type is straightforward: a specific member of the enum is assigned to a variable or constant. Alternatively, enums can also be initialized with raw values. Here we initialize a constant of type, AmericanLeagueWest
, using a raw value:
let myFavoriteTeam = AmericanLeagueWest(rawValue: "Oakland")
To test out the latter initialization method, I wrote the following:
enum ShoeStyleTypeTwo: Int {
case mules
case spectators
case mocassins
case flats
}
var myMuleCollection = ShoeStyleTypeTwo(rawValue: 6)
print(myMuleCollection.rawValue)
However, upon compiling, I get the following error:
Value of optional type 'ShoeStyleTypeTwo?' must be unwrapped to refer to member 'rawValue' of wrapped base type 'ShoeStyleTypeTwo'
Could someone please tell me why this is generating an error? My lessons say nothing about encountering this error for some reason. Perhaps something is wrong with my code?