Re: getResourceValue:forKey:error: Unrecognized Selector
Re: getResourceValue:forKey:error: Unrecognized Selector
- Subject: Re: getResourceValue:forKey:error: Unrecognized Selector
- From: Kyle Sluder <email@hidden>
- Date: Fri, 28 Oct 2011 22:59:33 -0700
On Oct 26, 2011, at 8:20 PM, GW Rodriguez <email@hidden> wrote:
> if([[[info draggingPasteboard] types] containsObject:NSURLPboardType] ) {
> NSString *availableType = [[info draggingPasteboard] availableTypeFromArray:firstType];
> NSString *fileType;
> NSURL *url;
> NSArray *filesList = [[info draggingPasteboard] propertyListForType:availableType];
NSURL is not a property list type. You should use the new NSPasteboardReading API (available since 10.6), or if you need backwards compatibility with 10.5, use +[NSURL URLFromPasteboard:] declared in <AppKit/NSPasteboard.h>.
>
> for (int i=0; i<[filesList count]; ++i) {
> url = [filesList objectAtIndex:i];
>
> if ([url getResourceValue:&fileType forKey:NSURLTypeIdentifierKey error:NULL]) {
This will fail silently (fileType==nil, error==NULL) if the URL is not a file:// URL to an existing file on disk. -getResourceValue:forKey:error:, when given one of the file system resource keys, is really just a wrapper around other APIs like -[NSWorkspace typeOfFile:error:]. If someone has put an http:// URL on the pasteboard, you need to be ready to handle it.
--Kyle Sluder_______________________________________________
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