Swift: How to use associated values in enumeration ?

Enumeration in Swift can store unique associated values of different types for individual cases. The values may belong to any type such as ( Int, Double, Float or String).

The above code example can be explained as follows: Define a enumeration of type CustomerKYC which can take one of the four values such as: dob, address, state and gender.Each individual cases can further associate them with different types of value.

When a variable is assigned with a enum type, it can at-most carry a single value type at any point of time. The value assigned to a variable can be changed to another associated type any time.

Leave a Reply