​Fast is really a effective and user-friendly development language for macOS, iOS, watchOS and...

Page 107

Swift

switch lang { case .Swift: println("Welcome to Swift") case .Closures: println("Welcome to Closures") default: println("Introduction") } When we run the above program using playground, we get the following result: Welcome to Closures Swift enumeration does not assign its members default value like C and Objective C. Instead the members are explicitly defined by their enumeration names. Enumeration name should start with a capital letter (Ex: enum DaysofaWeek). var weekDay = DaysofaWeek.Sunday Here the Enumeration name 'DaysofaWeek' is assigned to a variable weekday.Sunday. It informs the compiler that the datatype belongs to Sunday will be assigned to subsequent enum members of that particular class. Once the enum member datatype is defined, the members can be accessed by passing values and further computations.

Enumeration with Switch Statement Swift 'Switch' statement also follows the multi way selection. Only one variable is accessed at a particular time based on the specified condition. Default case in switch statement is used to trap unspecified cases. enum Climate{ case India case America case Africa case Australia }

var season = Climate.America season = .America switch season { 95


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.