Swift dynamic type checking for structs?
<p>I'm confused about dynamic type checking in Swift.</p>

<p>Specifically, I have a weirdo case where I want to, essentially, write (or find) a function:</p>

<pre><code>func isInstanceOf(obj: Any, type: Any.Type) -&gt; Bool
</code></pre>

<p>In Objective-C, this is <code>isKindOfClass</code>, but that won't work because <code>Any.Type</code> includes Swift structs, which are not classes (much less <code>NSObject</code> subclasses).</p>

<p>I can't use Swift <code>is</code> here, because that requires a hardcoded type.</p>

<p>I can't use <code>obj.dynamicType == type</code> because that would ignore subclasses.</p>

<p>The <a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ClassesAndStructures.html" rel="noreferrer">Swift book</a> seems to suggest that this information is lost, and not available for structs at all:</p>

<blockquote>
  <p>Classes have additional capabilities that structures do not:</p>
  
  <p>...</p>
  
  <ul>
  <li>Type casting enables you to check and interpret the type of a class instance at runtime.</li>
  </ul>
</blockquote>

<p>(On the Type Casting chapter, it says "Type casting in Swift is implemented with the is and as operators", so it seems to be a broader definition of "type casting" than <a href="https://en.wikipedia.org/wiki/Type_casting_(computer_programming)" rel="noreferrer">in other languages</a>.)</p>

<p>However, it can't be true that <code>is</code>/<code>as</code> don't work with structures, since you can put Strings and Ints into an <code>[Any]</code>, and pull them out later, and use <code>is String</code> or <code>is Int</code> to figure out what they were.  The Type Casting chapter of the Swift Book does exactly this!</p>

<p>Is there something that's as powerful as <code>isKindOfClass</code> but for any Swift instances?  This information still must exist at runtime, right?</p>