title: How to display OptionSet values in human-readable form?
body: <p>Swift has the OptionSet type, which basically adds set operations to C-Style bit flags. Apple is using them pretty extensively in their frameworks. Examples include the options parameter in <code>animate(withDuration:delay:options:animations:completion:)</code>.</p>
  <p>On the plus side, it lets you use clean code like:</p>
  <pre><code>options: [.allowAnimatedContent, .curveEaseIn]
  </code></pre>
  <p>However, there is a downside as well.</p>
  <p>If I want to display the specified values of an <code>OptionSet</code>, there doesn't seem to be a clean way to do it:</p>
  <pre><code>let options: UIViewAnimationOptions = [.allowAnimatedContent, .curveEaseIn]
  print(&quot;options = &quot; + String(describing: options))
  </code></pre>
  <p>Displays the very unhelpful message:</p>
  <blockquote>
  <p>options = UIViewAnimationOptions(rawValue: 65664)</p>
  </blockquote>
  <p>The docs for some of these bit fields expresses the constant as a power-of-two value:</p>
  <pre><code>flag0    = Flags(rawValue: 1 &lt;&lt; 0)
  </code></pre>
  <p>But the docs for my example OptionSet, <code>UIViewAnimationOptions</code>, doesn't tell you anything about the numeric value of these flags and figuring out bits from decimal numbers is not straightforward.</p>
  <h2>Question:</h2>
  <p>Is there some clean way to map an OptionSet to the selected values?</p>
  <p>My desired output would be something like:</p>
  <blockquote>
  <p>options = UIViewAnimationOptions([.allowAnimatedContent, .curveEaseIn])</p>
  </blockquote>
  <p>But I can't think of a way to do this without adding messy code that would require me to maintain a table of display names for each flag.</p>
  <p>(I'm interested in doing this for both system frameworks and custom OptionSets I create in my own code.)</p>
  <p>Enums let you have both a name and a raw value for the enum, but those don't support the set functions you get with OptionSets.</p>