Posts

Showing posts from July, 2019

Enums in Swift

Enums in Swift "Enums" define a finite state of any entity. This entity could be a direction in a compass, name of planets, day's in a weekend, brands of vehicles and so on so forth. This behavior of defining a finite state is extended to the programming world of software languages in a more readable and understandable format for developers. ex: Swift In Swift the basic syntax would be as follows enum <name> {     case <case> } To express a enum of Days in  a week we can write the code as shown below. Here <name> is name of the enum , DaysInWeek and I have give a Type to It, which is  Integer. enum DaysInAWeek: Int {     case Sunday = 0     case Monday,Tuesday,Wednesday,Thursday,Friday     case Saturday      } To initialize a var with enum value Monday , it can be written as follows. let  monday =  DaysInAWeek . Monday Another way to initialize it is as follows. let  monday =  DaysInAWeek (raw