title: How do I declare, create, and use method pointers in Swift?
body: <p>I'm not talking about pointers to C functions, but to a method within a Swift type.</p>
  
  <pre><code>struct Test: GeneratorType {
      var methodPointer: mutating () -&gt; Bool?  // Non-working guess
      var which: Bool
  
      init() {
          which = false
          methodPointer = which ? &amp;testMethod1 : &amp;testMethod2  // Also non-working guess
      }
  
      //...
  }
  </code></pre>
  
  <p>The compiler says "<code>mutating</code>" isn't legal as part of a function declaration. (Actually, it just suggests a semi-colon there.)  And for the pointer initialization (after I remove <code>mutating</code>), the compiler thinks I'm trying to call the functions and use their results instead.  I want to use the methods as objects in-and-of themselves here, not as a function call.  Later on I want to use the pointed-to method within <code>next</code>; without figuring this out, I'll have to resort to an enumeration flag and manually choosing which method to call within <code>next</code>.</p>
  
  <p>I hope there's some part of closure mechanics that allows this.  Maybe something like <a href="http://oleb.net/blog/2014/07/swift-instance-methods-curried-functions/" rel="nofollow" title="Instance Methods are Curried Functions in Swift">this page, which describes functions returning functions</a>. But none of the examples I've seen mention <code>mutating</code> methods.</p>