title: iOS Swift2 recording preparation may create empty/unused files
body: <h2>Overview</h2>
  
  <p>I found a lag after hitting my "Record" button, so I came up with a solution which causes other problems. My solution is to prepare the audio recorder very often, but this will always create an empty file, which sometimes is never recorded to. NOTE that this only happens on a physical device, not in simulation.</p>
  
  <h2>Questions</h2>
  
  <p>Is there a way to either (1) reduce the lag when recording a file without creating empty files or (2) efficiently clean up non-recorded files? It seems that (2) should be run every time the app or view loads.</p>
  
  <h2>Code</h2>
  
  <p>Part 0: my variables</p>
  
  <pre><code>var audioRecorder : AVAudioRecorder!
  var currentAudioFilename = "" // the file to play
  var nextAudioFilename = "" // the file to record
  let audioSession = AVAudioSession.sharedInstance()
  </code></pre>
  
  <p>Part 1: my setupRecorder()</p>
  
  <pre><code>do {
              try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
              nextAudioFilename = NSUUID().UUIDString + ".wav"
              try audioRecorder = AVAudioRecorder(URL: self.directoryURL(nextAudioFilename)!,
                                                  settings: recordSettings)
  }
  catch {}
  audioRecorder.prepareToRecord()
  audioRecorder.delegate = self
  print("Recorder setup with new name: current-" + currentAudioFilename + " next-" + nextAudioFilename + " forceSetup-\(forceSetup)")
  </code></pre>
  
  <p>Part 2: </p>
  
  <pre><code>// set player's filename to recorder's filename
  currentAudioFilename = nextAudioFilename
  
  if !audioRecorder.recording {
      do {
          try audioSession.setActive(true)
          audioRecorder.record()}
          catch {print("could activate the recorder")
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Thanks in advance!</p>
  
  <p>Dan</p>