How to check url is image or video?

You can check image like below

let url1 : String = "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
        let imageExtensions = ["png", "jpg", "gif"]
        //...
        // Iterate & match the URL objects from your checking results
        let url: URL? = NSURL(fileURLWithPath: url1) as URL
        let pathExtention = url?.pathExtension
            if imageExtensions.contains(pathExtention!)
            {
                print("Image URL: \(String(describing: url))")
                // Do something with it
            }else
            {
               print("Movie URL: \(String(describing: url))")
            }

Same you can check for video


Swift 3

Hope will help you

extension String {
    public func isImageType() -> Bool {
        // image formats which you want to check
        let imageFormats = ["jpg", "png", "gif"]

        if URL(string: self) != nil  {

            let extensi = (self as NSString).pathExtension

            return imageFormats.contains(extensi)
        }
        return false
    }
}

Tags:

Ios

Swift