SWIFT ENUMERATIONS

Enumeration:

Enumerations are similar to structure of C. As it is
1. Enumerations can be used within a class or it can be declared outside of the class globally and values are accessed via instance of those enumerations.
2. It can be extended by ensuring standard protocol functionality.

Syntax:

enum EnumerationName: <Type>(Optional){
//enum values
}

USAGE:

Here, We define enumeration for week days:

Finally call the above method:

self.toDo()

HOW IT WORKS

Here the day from getWeekName() returns week day of today’s date and that string is checked with enum’s rawvalue and the corresponding scope statements get executed. Similary if we want to change the text you can change from one place for all over cheking if we use enum. Otherwise you have to change all over the class where you implemented with raw week day string or anyother date. Try to use globalisation and Keep your code compact.

Happy Coding!❤️

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store