• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Filter an array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Filter an array (From: Chris Paveglio <email@hidden>)
 >Re: Filter an array (From: Mike Abdullah <email@hidden>)
 >Re: Filter an array (From: Wade Tregaskis <email@hidden>)

  • Prev by Date: Re: Running Cocoa from a dynamic library
  • Next by Date: Re: Telling Auto Save, "No, I'm busy now"
  • Previous by thread: Re: Filter an array
  • Next by thread: Re: Filter an array
  • Index(es):
    • Date
    • Thread