​Swift is just a powerful and spontaneous development language for macOS, iOS, watchOS and tvO...

Page 161

Swift

println("Student name is specified") }

let blankname = studrecord(stname: "") if blankname == nil { println("Student name is left blank") } When we run the above program using playground, we get the following result: Student name is specified Student name is left blank

Failable Initializers for Enumerations Swift language provides the flexibility to have Failable initializers for enumerations too to notify the user when the enumeration members are left from initializing values. enum functions { case a, b, c, d init?(funct: String) { switch funct { case "one": self = .a case "two": self = .b case "three": self = .c case "four": self = .d default: return nil } } }

let result = functions(funct: "two") if result != nil { 149


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