Swift Tutorial - Tutorialspoint

(backadmin) #1

An enumeration is a user-defined data type which consists of set of related values.
Keyword enum is used to defined enumerated data type.


Enumeration Functionality


Enumeration in swift also resembles the structure of C and Objective C.


 It is declared in a class and its values are accessed through the instance of that
class.

 Initial member value is defined using enum intializers.

 Its functionality is also extended by ensuring standard protocol functionality.

Syntax


Enumerations are introduced with the enum keyword and place their entire definition
within a pair of braces:


enum enumname {
// enumeration values are described here
}

For example, you can define an enumeration for days of week as follows:


enum DaysofaWeek {
case Sunday
case Monday
---
case Saturday
}

Example


enum names{
case Swift
case Closures
}
var lang = names.Closures
lang = .Closures

18. SWIFT – ENUMERATIONS

Free download pdf