Using CFNotificationCallback in Swift, or, @convention(c) blocks in Swift
<p>I am trying to listen to CoreTelephony notifications using the (now private) <code>CTTelephonyCenterAddObserver</code> C function and <code>CFNotificationCallback</code> callback blocks.</p>

<p>My bridging header (to extern the private C functions):</p>

<pre><code>#include &lt;CoreFoundation/CoreFoundation.h&gt;

#if __cplusplus
extern "C" {
#endif

#pragma mark - API

    /* This API is a mimic of CFNotificationCenter. */

    CFNotificationCenterRef CTTelephonyCenterGetDefault();
    void CTTelephonyCenterAddObserver(CFNotificationCenterRef center, const void *observer, CFNotificationCallback callBack, CFStringRef name, const void *object, CFNotificationSuspensionBehavior suspensionBehavior);
    void CTTelephonyCenterRemoveObserver(CFNotificationCenterRef center, const void *observer, CFStringRef name, const void *object);
    void CTTelephonyCenterRemoveEveryObserver(CFNotificationCenterRef center, const void *observer);

    void CTIndicatorsGetSignalStrength(long int *raw, long int *graded, long int *bars);

#pragma mark - Definitions

    /* For use with the CoreTelephony notification system. */
    extern CFStringRef kCTIndicatorsSignalStrengthNotification;

#if __cplusplus
}
#endif
</code></pre>

<p>My Swift code:</p>

<pre><code>let callback: CFNotificationCallback = { (center: CFNotificationCenter?, observer: UnsafeRawPointer?, name: CFString?, object: UnsafeRawPointer?, info: CFDictionary?) -&gt; Void in
    // ...
}

CTTelephonyCenterAddObserver(CTTelephonyCenterGetDefault().takeUnretainedValue(), nil, callback, kCTIndicatorsSignalStrengthNotification.takeUnretainedValue(), nil, .coalesce)
</code></pre>

<p>However, I can't get the signature of my <code>completion</code> variable to match the requirements of the <code>CFNotificationCallback</code> typealias.</p>

<blockquote>
<pre><code>Cannot convert value of type
'(CFNotificationCenter?, UnsafeRawPointer?, CFString?, UnsafeRawPointer?, CFDictionary?) -&gt; Void'
to specified type
'CFNotificationCallback' (aka '@convention(c) (Optional&lt;CFNotificationCenter&gt;, Optional&lt;UnsafeMutableRawPointer&gt;, Optional&lt;CFNotificationName&gt;, Optional&lt;UnsafeRawPointer&gt;, Optional&lt;CFDictionary&gt;) -&gt; ()')
</code></pre>
</blockquote>

<p>How can I get <code>@convention(c)</code> closures to play nicely in Swift?</p>