what is Swift Enumeration !
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 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.
import UIKit
enum Example
{
case A
case B
case C
case D
}
class ViewController: UIViewController
{
override func viewDidLoad() {
super.viewDidLoad()
var example2 = Example.A
example2 = .B
switch example2
{
case .A:
print("Print: A")
default:
print("Print: B")
}
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Discover more from mycodetips
Subscribe to get the latest posts sent to your email.