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)
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
// 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)
enum Season {
case spring, summer, autumn, winter
}