title: Swift -- Audio Recorder/Voice Changer App: How are these functions related?
body: <p>I have two functions in an audio recorder app I am creating (following a Udacity tutorial.) I am trying to understand how these two functions are related:</p>
  
  <pre><code>    @IBAction func recordButton(sender: UIButton) {
  
      recordB.hidden = true
      inProgress.hidden = false
      stopButtonHide.hidden = false
      let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
  
      let currentDateTime = NSDate()
      let formatter = NSDateFormatter()
      formatter.dateFormat = "ddMMyyyy-HHmmss"
      let recordingName = formatter.stringFromDate(currentDateTime)+".wav"
      let pathArray = [dirPath, recordingName]
      let filePath = NSURL.fileURLWithPathComponents(pathArray)
      println(filePath)
  
      var session = AVAudioSession.sharedInstance()
      session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
  
  
      audioRecorder = AVAudioRecorder(URL: filePath, settings: nil, error: nil)
      audioRecorder.delegate = self
      audioRecorder.meteringEnabled = true
      audioRecorder.prepareToRecord()
      audioRecorder.record()
  }
  
  func audioRecorderDidFinishRecording(recorder: AVAudioRecorder!, successfully flag: Bool) {
      if(flag) {
          recordedAudio = RecordedAudio()
          recordedAudio.filePathUrl = recorder.url
          recordedAudio.title = recorder.url.lastPathComponent
          self.performSegueWithIdentifier("stopRecording", sender: recordedAudio)
      } else {
          println("Recording was not succesful")
          recordB.enabled = true
          stopButtonHide.hidden = true
      }
  
  }
  </code></pre>
  
  <p>The first function starts a recording (as I understand it), creates and stores an audio file (names it and gets it a path.) The second function checks to see if the recording is finished. My problem is that I can't see how the two functions connect. How does the second function know to check the recording in the first function? There is a separate class called RecordedAudio.swift that has  two variables:</p>
  
  <pre><code>import Foundation
  
  class RecordedAudio: NSObject{
  var filePathUrl: NSURL!
  var title: String!
  }
  </code></pre>
  
  <p>Why do I need this class? What is the purpose of this class (I know it is the model part of MVC but that's it)? I am trying to understand what is going on in my code as it wasn't that clear to me from the tutorial I am following.</p>