title: How to fix: "49: CreateDataFile failed"
body: <p>I am trying to write a simple audio recorder in swift, following tutorials, but for some reason the recorder fails when running .record() and throws the following error</p>
  
  <p>I have tried different settings for the file recording and changing the file location, no luck.</p>
  
  <pre><code>    let audioFilename = getFileURL(tag: tag)
  
      let settings = [
          AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
          AVSampleRateKey: 44100.0,
          AVNumberOfChannelsKey: 1,
          AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
          ] as [String : Any]
  
      do {
  
          audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)
          audioRecorder.delegate = self
          audioRecorder.record()}
  </code></pre>
  
  <p>Also the getFileURL methods:</p>
  
  <pre><code>func getFileURL(tag: Int) -&gt; URL {
  
      let path = getDocumentsDirectory().appendingPathComponent("\(HelperFunctions.getRecordingName(tag: tag)).m4a")
  
      return path as URL
  
  }
  func getDocumentsDirectory() -&gt; URL {
      let paths = FileManager.default.urls(for: .applicationDirectory, in: .userDomainMask)
      return paths[0]
  }
  </code></pre>
  
  <p>I get the "49:  CreateDataFile failed" error where should be none</p>