Enumerations are used to implement certain functions for a particular class or struct, and, similarly, enumerations can easily define a tool class or struct to be used for a complex type, and in order to do so, Swift allows you to define nested types that define nested, enumerated, class, and struct in the supported types.
To nest another type within a type, write the definition of a nested type within {} of its outer type, and define multilevel nesting as needed
struct blackjackcard{
Nested enumerations
Enum Suit:character {
Case spades = "?", Hearts = "?", Diampnds = "?", Clubs = "?"
}
Nested Rank Enumeration
Enum Rank:int {
Case 2, Three,four, Five, Six, Seven, Eight, Nine, Ten
Case Jack,queen,king,ace
struct Values {
Let First:int,second:int?
}
var values:values{
Switch Self {
Case. Ace:
Return Values.init (first:1, Second:11)
Case. Jack,. QUeen,. King:
Return Values.init (First:10, Second:nil)
Default
Return Values.init (First:self.rawValue, Second:nil)
}
}
}
Properties and methods of Blackjackcard
Let Rank:rank, Suit:suit
var description:string{
var output = "Suit is \ (suit.rawvalue)"
Output + = "value is \ (Rank.values.first)"
If let second = Rank.values.second {
Output + = "or \ (second)"
}
Return output
}
}
Referencing nested types
When a nested type is externally referenced, prefix the type name of the nested type with the type name of its outer type
Let Heartssymbol = BlackjackCard.Suit.Hearts.rawValue
Swift Learning-22--Nested types