title: swift struct nested in function
body: <p>Just for fun I tested out, if such a function is actually working:</p>
  
  <pre><code>func exampleFunction() -&gt; Any {
      struct Example {
          let x: Int
      }
      let example = Example(x: 2)
      return example
  }
  </code></pre>
  
  <p>And surprisingly it is. My question is now: Is it able to access for example <code>x</code> from the function? Of course this doesn't work:</p>
  
  <pre><code>let example = exampleFunction()
  print(example.x)         
  //Error: Value of type 'Any' has no member 'x'
  </code></pre>
  
  <p>It has to be type casted first, but with which type?</p>
  
  <pre><code>let example = exampleFunction()
  print((example as! Example).x)
  //Of course error: Use of undeclared type 'Example'
  
  print((example as! /* What to use here? */).x)
  </code></pre>
  
  <p>Surprisingly <code>print(type(of: example))</code> prints the correct string <code>Example</code></p>