title: How to check if the jpg / pdf file exists under the selected url?
body: <p>In case I want to check if the file exists on my iPhone, just use the following code:</p>
  
  <pre><code>  let filePath = fileName.path
           let fileManager = FileManager.default
           if fileManager.fileExists (atPath: filePath) {
  
  }
  </code></pre>
  
  <p>How can I check if there is a pdf / jpg / png file at the URL:
  www.myname.com/files/file1.jpg or www.myname.com/files/file2.pdf etc.?</p>
  
  <p>Could I ask for an example of such a function - but for files on internet web servers?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>func remoteFileExistsAt(url: URL, completion: @escaping (Bool) -&gt; Void) {
      let checkSession = URLSession.shared
      var request = URLRequest(url: url)
      request.httpMethod = "HEAD"
      request.timeoutInterval = 1.0 // Adjust to your needs
  
      let task = checkSession.dataTask(with: request) { (data, response, error) -&gt; Void in
          if let httpResp = response as? HTTPURLResponse {
              completion(httpResp.statusCode == 200)
          }
      }
      task.resume()
  }
  </code></pre>
  
  <p>Is it possible to check in this function whether the file is of JPG or PNG type? If so - then we also return true, and if not, false?</p>