So I am trying to implement the Superpowered library in Swift, and am getting stuck around initialisation with a callback. How would I convert that line:
    __unsafe_unretained Superpowered *self = (__bridge Superpowered *)clientdata;
into Swift?
Here is the simplified Objective C implementation:
@implementation Superpowered {
    SuperpoweredIOSAudioIO *audioIO;
    SuperpoweredBandpassFilterbank *filters;
    unsigned int samplerate;
}
static bool audioProcessing(void *clientdata, float **buffers, unsigned int inputChannels, unsigned int outputChannels, unsigned int numberOfSamples, unsigned int samplerate, uint64_t hostTime) {
    __unsafe_unretained Superpowered *self = (__bridge Superpowered *)clientdata;
    if (samplerate != self->samplerate) {
        self->samplerate = samplerate;
    };
    // Update position.
    self->lastNumberOfSamples = numberOfSamples;
    return false;
}
- (id)init {
    self = [super init];
    if (!self) return nil;
    samplerate = 44100;
    audioIO = [[SuperpoweredIOSAudioIO alloc] initWithDelegate:(id<SuperpoweredIOSAudioIODelegate>)self preferredBufferSize:12 preferredMinimumSamplerate:44100 audioSessionCategory:AVAudioSessionCategoryRecord channels:2 audioProcessingCallback:audioProcessing clientdata:(__bridge void *)self];
    [audioIO start];
    return self;
}
And here is the start of my Swift version:
func bridge<T : AnyObject>(obj : T) -> UnsafeMutableRawPointer {
    return UnsafeMutableRawPointer(Unmanaged.passUnretained(obj).toOpaque())
    // return unsafeAddressOf(obj) // ***
}
func bridge<T : AnyObject>(ptr : UnsafeMutableRawPointer) -> T {
    return Unmanaged<T>.fromOpaque(ptr).takeUnretainedValue()
    // return unsafeBitCast(ptr, T.self) // ***
}
open class EchoesEngine: NSObject, CLLocationManagerDelegate, SuperpoweredIOSAudioIODelegate {
    public var audioIO:SuperpoweredIOSAudioIO
    static var lastNumberOfSamples:UInt32!
    static var samplerate:UInt32!
    override init() {
        super.init()
        audioIO = SuperpoweredIOSAudioIO.init(delegate: self, preferredBufferSize: 12, preferredMinimumSamplerate: 44100, audioSessionCategory: AVAudioSessionCategoryPlayAndRecord, channels: 2, audioProcessingCallback: EchoesEngine.audioProcessingCallback, clientdata: bridge(obj: self))
        …
    }
    @objc static let audioProcessingCallback : @convention(c) (UnsafeMutableRawPointer?, UnsafeMutablePointer<UnsafeMutablePointer<Float>?>?, UInt32, UInt32, UInt32, UInt32, UInt64) -> Bool = {
        (clientdata, buffers, inputChannels, outputChannels, numberOfSamples, _samplerate, hostTime) in
        /*
        let unsafePointer = Unmanaged<EchoesEngine>.fromOpaque(clientdata!).takeUnretainedValue()
        let pointer = AutoreleasingUnsafeMutablePointer<EchoesEngine>(unsafePointer)
        */
        self = bridge(ptr: clientdata!)
        if samplerate != _samplerate {
            samplerate = _samplerate
        }
        lastNumberOfSamples = numberOfSamples
        return false
    }
 
    