title: Check if a URL is a video URL or PHOTO URL
body: <p>I have a textview in which a user is supposed to enter a url. First I am checking the validity of the URL. Once the validity is confirmed, I need to check if It's a video url or photo url. I have two arrays of all possible video (MP4, MOV etc) and photo (JPG, PNG) file formats and I get an appropriate message if the url contains any element from those two arrays.</p>
  
  <p>Here is a sample instagram video link..
  For example: <a href="https://www.instagram.com/p/B-PilcbFy2w/" rel="nofollow noreferrer">https://www.instagram.com/p/B-PilcbFy2w/</a></p>
  
  <p>The following Link is a valid video link but it does not contain any video file formats like (MOV, MP4 etc). How can I validate such links? </p>
  
  <p>I know the concept of regular expressions to validate such things but for that I'll have to implement a bunch of IF statements which is not an efficient way. The sample video Link is just an example. I need to validate all kind of video links whether they are from social media platforms or whatever. Help regrading this will really be appreciated.</p>
  
  <p>Here is my sample code..</p>
  
  <pre><code>@IBOutlet weak var textVW: UITextView!
  
  @IBAction func validateButton(_ sender: UIButton) {
  
  
      let userInputURL = URL(string: textVW.text)
  
      if userInputURL != nil &amp;&amp; userInputURL?.scheme != nil &amp;&amp; userInputURL?.host != nil {
          //  - a scheme (like http://)
          //  - a host (like stackoverflow.com)
  
          print("Valid URL..")
  
          // Now checking url type, if its a video or image url..
          checkURLType(inputURL: userInputURL!)
  
      }
  
      else {
          print("Invalid URL..")
      }
  }
  
  func checkURLType(inputURL : URL) {
  
      // Most commom image types..
      let imageExtensions = ["png", "jpg", "gif", "tif"]
  
      // Most cmmon video types..
      let videoExtensions = ["WEBM", "MPG", "MPEG", "MPE", "MP4", "M4P", "M4V", "AVI", "WMV", "MOV"]
  
      let url: URL? = NSURL(fileURLWithPath: inputURL.path) as URL
      let pathExtention = url?.pathExtension
  
      if imageExtensions.contains(pathExtention!)
          {
              print("Image URL: \(String(describing: url))")
  
          }
  
      else if videoExtensions.contains(pathExtention!)
          {
               print("Video URL: \(String(describing: url))")
          }
  
          else
          {
               print("Does Not Exist: \(String(describing: url))")
          }
  
  
  }
  </code></pre>