I tried to convert this code, which I had from this example (in Objective-c), with no luck.
String *path; // contains the file path // Get the UTI from the file extension: CFStringRef pathExtension = (__bridge_retained CFStringRef)[path pathExtension]; CFStringRef type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL); CFRelease(pathExtension); // The UTI can be converted to a mime type: NSString *mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType); if (type != NULL) CFRelease(type);
My code is
import MobileCoreServices let path: String? let pathExt = path.pathExtension as CFStringRef let type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL); let mimeType = UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType) if type != Null CFRelease(type)
All I want to do is find out if the file is an image or a video file
source share