title: Swift function forward-declaration or prototype
body: <p>In Objective-C (or C in general), if I'm going to have two files like</p>
  
  <p><strong>main.m:</strong></p>
  
  <pre class="lang-m prettyprint-override"><code>void foo();
  
  int main (int argc, const char * argv[])
  {
      foo();
      return 0;
  }
  </code></pre>
  
  <p><strong>foo.m:</strong></p>
  
  <pre class="lang-m prettyprint-override"><code>void foo() {
      // do something
  }
  </code></pre>
  
  <p>I can compile main.m to main.o without even having foo.m, then compile foo.m and link with main.o:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ clang -c main.m
  
  # later
  $ clang main.o foo.m -o FooExecutable
  </code></pre>
  
  <p>My understanding is that the forward-declaration or prototype on the first line of main.m is what makes this work.</p>
  
  <p>Is there a way to create the same kind of setup in Swift?  I haven't found a way to make a corresponding main.swift compile.</p>
  
  <p><strong>main.swift:</strong></p>
  
  <pre><code>// How do I tell the compiler to trust me that foo() will be implemented?
  
  foo()
  </code></pre>
  
  <p><strong>foo.swift:</strong></p>
  
  <pre><code>func foo() {
      // do something
  }
  </code></pre>
  
  <p>And then:</p>
  
  <pre class="lang-sh prettyprint-override"><code># This works:
  $ swiftc main.swift foo.swift -o FooExecutable
  
  # This doesn't:
  $ swiftc -emit-object main.swift
  
  main.swift:3:1: error: use of unresolved identifier 'foo'
  foo()
  ^~~
  </code></pre>