Defining enumerations
Enum Mapdirection {
Case North
Case South
Case East
Case West
Func simpledescription (), String {
Switch Self {
Case. North:
Return "North"
Case. South:
Return "South"
Case. East:
Return "East"
Case. West:
Return "West"
}
}
}
Using enumerations
Let en:mapdirection = Mapdirection.north
var en = Mapdirection.north
Print (En.simpledescription ())
En =. West
Print (En.simpledescription ())
Define Structure body
struct Summation {
var addend:int
var augend:int
var addstring:string
var augstring:string
Func sum (), Int {
return addend + augend
}
Func sumstring (), String {
return addstring + augstring
}
}
Create a struct body
Let newstruct = summation (addend:10, augend:20)
Let newstruct = summation (Addend:10, augend:20, addstring: "Newstruct", augstring: "Newstruct")
Using methods in the structure body
Let sum = Newstruct.sum ()
Print (sum)
Print (newstruct.sumstring ())
Swift defines enumerations and struct bodies and uses