What is the best way to call into Swift from C? : <p>Calling into C from Swift is pretty simple, however I'm looking into making a bi-directional wrapper in C, so my C has to call Swift functions.</p>

<p>Right now, I can do this by declaring function pointers in C, and having my C functions call them after the Swift side has set them up to call code in Swift.</p>

<p>My C header file:</p>

<pre><code>typedef void (*callback_t)(void);

void callBackIntoSwift( callback_t cb );
</code></pre>

<p>My C implementation file:</p>

<pre><code>#include "stuff.h"
#include &lt;stdio.h&gt;

void callBackIntoSwift( callback_t cb )
{
    printf( "Will call back into Swift\n" );
    cb();
    printf( "Did call back into Swift\n" );
}
</code></pre>

<p>After including my C header file in the bridging header, I can do the following on the Swift side:</p>

<pre><code>let cb: callback_t = {
    someKindOfSwiftFunction()
}

callBackIntoSwift( cb )
</code></pre>

<p>Or even:</p>

<pre><code>callBackIntoSwift {
    someKindOfSwiftFunction()
}
</code></pre>

<p>Is there a better way to do this, where function pointers and callbacks are not needed? I'd like to let the C-side call <code>someKindOfSwiftFunction</code> directly … but when I try to apply <code>@convention (c)</code> to function declarations I get the message that the attribute can only be applied to types, and not declarations.</p>

<p>Any ideas or codebases in e.g. Github I can take a look at?</p>
