swift enum
enum WeatherType { case sun case cloud case rain case wind case snow } func getHaterStatus(weather: WeatherType) -> String? { if weather == .sun { return nil } else { return "Hate" } } getHaterStatus(weather: .cloud)
Source: www.hackingwithswift.com
define enum swift
Struct : Value Type | No Inheritance | No Deinitializers | No Type casting Class : Reference Type | Inheritance supported | Has Deinitializers | Type casting Common factors between struct and class: Both allows to define properties to store values Both allows to define methods Both allows to define subscripts Both allows to define initializers Both allows extension and protocols
how to enum use in swift
// MARK: Enumerations used in swift let result = "failure" let result2 = "failed" let result3 = "fail" enum Result { case success case failure } let res = Result.failure print(res)
Swift enum
enum Season { case spring, summer, autumn, winter }