what is Swift Enumeration !

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.

enum1

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.
}

}

 

tips & tricks

Join 7,714 other subscribers

interview questions


Algorithm Android Android Studio API APP Programming Apps AS400 blogging Browser CheatSheets Config CSS DATABASE dsa error Features GUI HTML HTML5 IDE installation Interview Questions IOS iPhone javascript Mac objective-c OneDrive OS Programming quicktips SDK SEO Settings SMO SQL swift swiftUI Teams Tips & Tricks Tools UI Web Wordpress Xcode


Archives

Discover more from CODE t!ps

Subscribe now to keep reading and get access to the full archive.

Continue reading