title: Nested Enums in Swift 4
body: <p>The current implementation of extracting data from long nested enums appears to be quite tedious and the upkeep of such structures laborious. Below is an example of an implementation I have and just wanted some input whether this is truly the correct way to extract data from these enums</p>
  
  <pre><code>import UIKit
  import Foundation
  
  enum HousingType {
      case House(HousingSubType)
      case Apartment(HousingSubType)
      case Mansion(HousingSubType)
  
      enum HousingSubType: CaseIterable {
          case Victorian
          case Modern
          case Standard
      }
  
      var name: String {
          switch self {
          case let .House(subtype):
              switch subtype {
              case .Modern:
                  return Structure.House.Modern.name
              case .Standard:
                  return Structure.House.Standard.name
              case .Victorian:
                  return Structure.House.Victorian.name
              }
          case let .Apartment(subtype):
              switch subtype {
              case .Modern:
                  return Structure.Apartment.Modern.name
              case .Standard:
                  return Structure.Apartment.Standard.name
              case .Victorian:
                  return Structure.Apartment.Victorian.name
              }
          case let .Mansion(subtype):
              switch subtype {
              case .Modern:
                  return Structure.Mansion.Modern.name
              case .Standard:
                  return Structure.Mansion.Standard.name
              case .Victorian:
                  return Structure.Mansion.Victorian.name
              }
          }
      }
  
      static var allCases: [HousingType] {
          return
              HousingType.HousingSubType.allCases.map(HousingType.House)
                  + HousingType.HousingSubType.allCases.map(HousingType.Apartment)
                  + HousingType.HousingSubType.allCases.map(HousingType.Mansion)
      }
  }
  
  enum Structure {
      enum House {
          enum Victorian {
              static let name = "Victorian House"
              static let rooms = 4
              static let bathrooms = 1
          }
          enum Modern {
              static let name = "Modern House"
              static let rooms = 4
              static let bathrooms = 4
          }
          enum Standard {
              static let name = "Standard House"
              static let rooms = 4
              static let bathrooms = 2
          }
      }
  
      enum Apartment {
          enum Victorian {
              static let name = "Victorian Apartment"
              static let rooms = 2
              static let bathrooms = 1
          }
          enum Modern {
              static let name = "Modern Apartment"
              static let rooms = 2
              static let bathrooms = 2
          }
          enum Standard {
              static let name = "Standard Apartment"
              static let rooms = 2
              static let bathrooms = 1
          }
      }
  
      enum Mansion {
          enum Victorian {
              static let name = "Victorian Mansion"
              static let rooms = 10
              static let bathrooms = 3
          }
          enum Modern {
              static let name = "Modern Mansion"
              static let rooms = 10
              static let bathrooms = 10
          }
          enum Standard {
              static let name = "Standard Mansion"
              static let rooms = 10
              static let bathrooms = 6
          }
      }
  }
  </code></pre>
  
  <p>Output for:  </p>
  
  <pre><code>for type in HousingType.allCases {
      print(type.name)
  }
  </code></pre>
  
  <p>Is:</p>
  
  <pre><code>Victorian House
  Modern House
  Standard House
  Victorian Apartment
  Modern Apartment
  Standard Apartment
  Victorian Mansion
  Modern Mansion
  Standard Mansion
  </code></pre>
  
  <p>And output for </p>
  
  <pre><code>let apartment = HousingType.Apartment(.Modern)
  print(apartment.name)
  </code></pre>
  
  <p>is:</p>
  
  <pre><code>Modern Apartment
  </code></pre>
  
  <p>I can easily obtain data from enums and iterate through all the cases, but as you can see, it's a ton of code to go through each possible case for a single variable <code>name</code>. As I add code to get <code>rooms</code> or <code>bathrooms</code> or as additional <code>HousingSubType</code> are added, the length of this implementation gets extremely long. </p>
  
  <p>Is there a better way to obtain variable <code>name</code> without having to explicitly write out each possible case through a series of switch statements? Is there a different implementation entirely I should look into when attempting to have a series of static variables of various types, subtypes, subsubtypes, etc?</p>