> Oh, I don't know how I missed this, but there's a very convenient
> -[NSArray pathsMatchingExtensions:] method already declared in
> NSPathUtilities.h:
> http://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-BBCHHAJJ
>
> So your entire problem boils down to one method call.
The docs don't state whether it's case sensitive or not. It also takes the
list as an NSArray rather than an NSSet, which is suboptimal.
>
>> // warning: typed in mail client
>> NSArray *validExtensions = [NSArray arrayWithObjects:@".tif", @".png",
>> @".eps", nil];
>> NSIndexSet *indexes = [myFilePaths
>> indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^(id
>> obj, NSUInteger idx, BOOL *stop) {
>> NSString *filePath = (NSString *)obj;
>> for (NSString *extension in validExtensions) {
>> if ([[string pathExtension] isEqualToString:extension])
>> return YES;
>> }
>>
If you were to go this approach, which I wouldn't recommend given the existence
of the convenience method above (assuming it's properly case-insensitive), do:
1) Use caseInsensitiveCompare:, not isEqualToString:.
2) Consider using an NSSet for the set of accepted extensions (though that will
mean ensuring they're all e.g. lowercase, both when inserting the accepted
values into the set and prior to checking for set membership).
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]