I study Swift. I have a C interface returning back to Swift-2 code:
let inputProc: @convention(c) (UnsafeMutablePointer<Void>, UnsafeMutablePointer<AudioUnitRenderActionFlags>, UnsafePointer<AudioTimeStamp>, UInt32, UInt32, UnsafeMutablePointer<AudioBufferList>) -> OSStatus = { (inRefCon, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData) in // do things here return noErr }
This works, but it's hard for me to watch, and my process of writing such code is very inconvenient: I copy the callback declaration, add = { (a, b, c, d, e) in , and then replace a, b, c in the tuple with the best names as I discover their types.
Is there any way to move the callback parameter names closer to their types?
Say by writing let inputProc = @convention(c) (inRefCon: UnsafeMutablePointer<Void>, ...) and allowing type inference to sort it? My attempts to guess the syntax failed.
Dan Beaulieu made a great proposal to use typealias . Fortunately, it already exists, and my code is getting a lot easier to look at:
let inputProc: AURenderCallback = { (inRefCon, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData) in return noErr }
But now the types of arguments are more mysterious than ever (although there is only one option - click). I'm starting to suspect that I cannot have a c-callback with nice localized argument declarations, which would make typealias better solution.