Swift: Implicitly assigned rawValues

In enumerations, we can provide default value for the cases. The values must be of same type. If we are to provide String values and Int values as default values to the enum cases, we don’t have to explicitly provide them.Swift can implicitly assign raw values for the enum cases.For string type, the name provided to the case will be the default rawValue.For integers, the implicit value for each case is one more than the previous case. If no value is set for integer type cases, the rawValue starts from 0.

Swift code


Leave a Reply