title: Are Swift functions assigned/passed by value or by reference?
body: <p>When a function in Swift is assigned to a variable or returned, as a nested function, from a higher-level function, is it passed by value or by reference? When I write:</p>
  
  <pre><code>func foo() -&gt; Bool
  {
      return false
  }
  
  var funcVar = foo
  </code></pre>
  
  <p>does <code>funcVar</code> receive a reference to <code>foo()</code>, or is a copy of <code>foo()</code> created and stored in memory with the "funcVar" name? Same question for the following code:</p>
  
  <pre><code>func otherfoo() -&gt; (Int) -&gt; ()
  {
      func bar(num :Int) {}
      return bar
  }
  
  var funcVar = otherfoo()
  </code></pre>
  
  <p>The second example in particular puzzles me because, if I call <code>funcVar(3)</code> I should not be able to access <code>bar</code> in the case functions are assigned/returned by reference, since <code>bar</code> is inside another function at the same scope of <code>funcVar</code>, but it still works (coming from a C++ background I'm just surprised it compiles).
  Could somebody please shed some light on the matter for me?</p>