title: How should I implement Default Associated Values with Swift Enums?
body: <p>Swift question is there a way of having an enum type with one case that can have an associated value.</p>
  
  <p>I have an API that gives me available filters, it's unlikely but possible that the API will add additional filter types. So if the API sends an unknown filter type I want to keep that information associated with the enum.</p>
  
  <p>Below are the different ideas I had about doing this.</p>
  
  <p>My first two tries didn't compile. My third try just feels a bit clunky.</p>
  
  <p>Does anyone have a better way of doing this? Do you think I just shouldn't use an enum for this problem?</p>
  
  <pre><code>typealias APIFilterIdentifier = String
  
  /* Does Not Compile */
  enum EnumTestAssociatedValeu: APIFilterIdentifier {
      case Unknown(APIFilterIdentifier)
      case Everyone = "everyone"
      case Team = "myteam"
  }
  
  /* Does not compile */
  enum EnumTestDefaultAssociatedValues: APIFilterIdentifier {
      case Unknown(APIFilterIdentifier)
      case Everyone(APIFilterIdentifier = "everyone")
      case Team(APIFilterIdentifier = "myteam")
  }
  
  /* Compiles but is there a better way? */
  enum EnumTestWithCustomInit {
  
      case Unknown(APIFilterIdentifier)
      case Everyone
      case Team
  
      init(filterIdentifier: APIFilterIdentifier) {
          let everyone: APIFilterIdentifier = EnumTestWithCustomInit.everyoneFilterIdentifier
          let team: APIFilterIdentifier = EnumTestWithCustomInit.teamFilterIdentifier
  
          switch filterIdentifier {
          case everyone:
              self = .Everyone
          case team:
              self = .Team
          default:
              self = .Unknown(filterIdentifier)
          }
      }
  
      func asIdentifer() -&gt; APIFilterIdentifier {
          switch self {
          case .Everyone:
              return EnumTestWithCustomInit.everyoneFilterIdentifier
          case .Team:
              return EnumTestWithCustomInit.teamFilterIdentifier
          case .Unknown(let filterIdentifier):
              return filterIdentifier
          }
      }
  
      private static var everyoneFilterIdentifier: APIFilterIdentifier {
          return "everyone"
      }
  
      private static var teamFilterIdentifier: APIFilterIdentifier {
          return "myteam"
      }
  }
  </code></pre>