I\'ve been trying to convert this code which I had from this example (in Objective-c) with no luck.
String *path; // contains the file path
// Get
You can use URL
method resourceValues(forKeys:)
to get the file URL TypeIdentifierKey
which returns the file uniform type identifier (UTI). You just need to check if the returned value is "com.apple.m4v-video" for videos, "public.jpeg" or "public.png" for images and so on. You can add a typeIdentifier property extension to URL to return the TypeIdentifierKey string value as follow:
Xcode 11 • Swift 5.1
extension URL {
var typeIdentifier: String? { (try? resourceValues(forKeys: [.typeIdentifierKey]))?.typeIdentifier }
var localizedName: String? { (try? resourceValues(forKeys: [.localizedNameKey]))?.localizedName }
}