simon.d simon.d - 1 year ago 157
Objective-C Question

Check NSURL for UTI / file type

I'm building an app that allows users to drop videos onto it. Given a list of dropped NSURL*s how do I make sure each one conforms to the
UTI type?

If I had an
, I would just use
openPanel.allowedFileTypes = @[@""];
and Cocoa would take care of it for me.

Thanks in advance!

Answer Source

This should work:

NSWorkspace *workspace = [NSWorkspace sharedWorkspace];

for (NSURL *url in urls) {
    NSString *type;
    NSError *error;
    if ([url getResourceValue:&type forKey:NSURLTypeIdentifierKey error:&error]) {
        if ([workspace type:type conformsToType:@""]) {
            // the URL points to a movie; do stuff here
    } else {
        // handle error

(You can also use UTTypeConformsTo() instead of the NSWorkspace method.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download