title: How to convert this var string to URL in Swift
body: <p>I need url filepath be a <a href="https://developer.apple.com/documentation/foundation/url" rel="noreferrer">URL</a> (NSURL in old versions of Swift). I have this:</p>
  
  <pre><code>let paths = NSSearchPathForDirectoriesInDomains(
          .documentDirectory, .userDomainMask, true)
  
  // NSString *documentsDirectory = [paths objectAtIndex:0];
  let documentsDirectory = paths[0] as String
  
  var filePath:String? = nil
  var fileNamePostfix = 0
  repeat {
      filePath =
      "\(documentsDirectory)/\(dateTimePrefix)-\(fileNamePostfix).mp4"
      fileNamePostfix += 1
  } while (FileManager.default.fileExists(atPath: filePath))
  </code></pre>
  
  <p>I need to convert this to URL for use in <code>self.fileOutput.startRecording(to: &lt;#outputFileURL: URL?#&gt;, recordingDelegate: &lt;#AVCaptureFileOutputRecordingDelegate?#&gt;)</code> method.</p>
  
  <p>I tried <code>filePath as? URL()</code> but it isn't correct.</p>