Re: Filter an array
Re: Filter an array
- Subject: Re: Filter an array
- From: Ken Thomases <email@hidden>
- Date: Sat, 30 Jul 2011 03:47:32 -0500
On Jul 29, 2011, at 11:09 AM, Wade Tregaskis wrote:
> for (NSString *path in paths) {
> NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
> NSString *uti = nil;
> NSError *error = nil;
>
> if ([url getResourceValue:&uti forKey:NSURLTypeIdentifierKey error:&error]) {
> for (NSString *supportedType in supportedTypes) {
> if (UTTypeConformsTo(uti, supportedType)) {
> // You have a match.
> }
> }
> } else {
> // Handle error
> }
> }
>
> There's a lot of nasty enumeration there, rather than hashtables which make me much happier, but I don't know of a better way off hand.
>
> However, -[NSURL getResourceValue:forKey:error:] is only available in iOS 4.0 and later. So you'll have to find another route if you're targeting earlier than that.
Don't know about iOS, but on Mac OS X if you're starting with a file path, you're probably better of using -[NSWorkspace typeOfFile:error:] rather than going through NSURL.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden