2

Printing all cases in an enum is super simple!

Now I need to print all cases in the nested enum. My enum is like:

enum OuterEnum: String, CaseIterable {
        
        case a = "A"
        case b = "B"
        
        enum InnerEnum: String, CaseIterable {
            case c = "C"
        }
}

If I try to print all elements by allCases property, only a & b are getting printed. But, my expectation is,

printEnumCases(OuterEnum.self) should print all the cases like

A
B
C

Can someone help in this?

Additional question: Also, I want to know about the difference between allCases & AllCases properties of an enum.

Thanks!!

Community
  • 1
  • 1
Confused
  • 3,846
  • 7
  • 45
  • 72
  • `allCases` is the instance value `AllCases` represent its type – Leo Dabus Jul 21 '19 at 21:24
  • this sould be fix your problem. [concatenate nested enum string in swift](https://stackoverflow.com/questions/49991478/concatenate-nested-enum-string-in-swift) – CAGRI COLAK Jul 22 '19 at 06:46
  • I don't want to include initialisers/variables in each enum. I just want to pass the entire enum to a function to print its whole elements. – Confused Jul 22 '19 at 10:23

0 Answers0