title: How do I create an instance of a class from the child of a Mirror object in Swift
body: <p>I am trying to understand why I am unable to create an instance of a class using a mirror in Swift.  In the playground, everything seems fine until the very last line of code below.</p>
  
  <p>So, here's the first example with the use of type(of:):</p>
  
  <pre><code>// First Example
  var s = String( "Foo" ) // Playground Output: Foo
  type(of: s) // Playground Output:  String.Type
  var typeClone = type( of: s ).init() // Playground Output: "" (as expected)
  </code></pre>
  
  <p>Everything works as expected.  Now, when I try to do this same sort of thing with a child found in a mirror object, the playground complains:</p>
  
  <pre><code>// Second Example
  class FooContainer {
     var s : String = "Foo"
  }
  
  var t = FooContainer()
  var tMirror = Mirror( reflecting: t ) // Output: Mirror for FooContainer
  tMirror.children.first! // Output: {some "s"}, value "Foo")
  
  type( of: tMirror.children.first!.value ) // Output: String.Type
  var typeClone2 = type( of: tMirror.children.first!.value ).init()
  </code></pre>
  
  <p>The line with "typeClone2" is the one that fails.  If I break down the expressions and inspect things, it seems like all of the types and values are similar, as in the first example.  But in the second case, the playground emits this error:</p>
  
  <p>Playground execution failed:</p>
  
  <blockquote>
    <p>error: Type Playground.playground:12:18: error: 'init' is a member of the >type; use 'type(of: ...)' to initialize a new object of the same dynamic >type
    var typeClone2 = type( of: tMirror.children.first!.value ).init()
                    ^
                                                              type(of:  )</p>
  </blockquote>
  
  <p>What do I have to do to make this work?  Thanks in advance!</p>