title: Swift callback functions
body: <p>I'm trying to use <a href="http://theamazingaudioengine.com/" rel="nofollow">The Amazing Audio Engine</a> to record some audio using Swift on OS X. To do this, I need to implement a callback function that will receive the audio and do something with it. The documentation has some <a href="http://theamazingaudioengine.com/doc/_receiving-_audio.html" rel="nofollow">examples</a> on how to do this with Objective-C:</p>
  
  <pre><code>@interface MyAudioReceiver : NSObject &lt;AEAudioReceiver&gt;
  @end
  @implementation MyAudioReceiver
  static void receiverCallback(__unsafe_unretained MyAudioReceiver *THIS,
   __unsafe_unretained AEAudioController *audioController,
   void *source,
   const AudioTimeStamp *time,
   UInt32 frames,
   AudioBufferList *audio) {
  
   // Do something with 'audio'
  }
  -(AEAudioReceiverCallback)receiverCallback {
   return receiverCallback;
  }
  @end
  ...
  id&lt;AEAudioReceiver&gt; receiver = [[MyAudioReceiver alloc] init];
  </code></pre>
  
  <p>or</p>
  
  <pre><code>id&lt;AEAudioReceiver&gt; receiver = [AEBlockAudioReceiver audioReceiverWithBlock:
   ^(void *source,
   const AudioTimeStamp *time,
   UInt32 frames,
   AudioBufferList *audio) {
   // Do something with 'audio'
  }];
  </code></pre>
  
  <p>This is as far as I got:</p>
  
  <pre><code>var audioController: AEAudioController? = nil
  audioController = AEAudioController(audioDescription: AEAudioStreamBasicDescriptionInterleaved16BitStereo, inputEnabled: true)
  do {
      try audioController?.start()
  } catch {
      NSLog("An error happened while starting AEAudioController.")
  }
  
  let receiver = MyAudioReceiver();
  audioController?.addInputReceiver(receiver)
  
  class MyAudioReceiver : NSObject, AEAudioReceiver {
      var receiverCallback: AEAudioReceiverCallback! {
          // what do I do here?
      }
  }
  </code></pre>
  
  <p>Now I'm getting an error in the <code>receiverCallback</code> property. Am I on the right track here or is my approach completely wrong?</p>
  
  <p>I can't figure out how to do the exact same thing in Swift. How would I do that?</p>