Swift: How to access all the enumeration cases using CaseIterable protocol?

Types that conform to ‘CaseIterable protocol’ can let us access their entire collection of values by using their ‘allCases’ property. For example, enumeration type without associated values.Sometimes we need to get the value of all the cases contained in a enumeration type. First we have to declare that our enumeration conforms to CaseIterable protocol. Then by using allCases property we can extract all the cases contained inside our enumeration to variable or constant.

 

 

 

Leave a Reply