Re: [Q] availableTypeFromArray returns NXFileContentsPboardType instead of NSFileContentsPboardType
Re: [Q] availableTypeFromArray returns NXFileContentsPboardType instead of NSFileContentsPboardType
- Subject: Re: [Q] availableTypeFromArray returns NXFileContentsPboardType instead of NSFileContentsPboardType
- From: "Michael Ash" <email@hidden>
- Date: Thu, 18 Dec 2008 16:55:34 -0500
On Thu, Dec 18, 2008 at 2:09 PM, JongAm Park
<email@hidden> wrote:
> Hello, all.
>
> I'm struggling to enable drag&dropping to Final Cut Pro's project window
> from my application.
>
> While I was trying to figure out how to, I found this strange thing.
>
> NSArray *supportedTypes = [NSArray
> arrayWithObject:NSFileContentsPboardType];
>
> NSString *matchingType = [pboard availableTypeFromArray:supportedTypes];
> if( [matchingType compare:@"NSFileContentsPboardType] == NSOrderedSame )
> {
> outputFileName = [NSString stringWithFormat:@"%@/Desktop/test.mov",
> NSHomeDirectory()];
> outputFileNameResult = [pboard
> readFileContentsType:NSFileContentsPboardType toFile:outputFileName];
> }
> ....
>
> I expected that the matchingType returned by calling availableTypeFromArray
> is @"NSFileContentsPboardType".
> But, in fact, it returns @"NXFileContentsPboardType".
> So, it doesn't reach the body of the if clause.
> Is this a bug?
It's a bug in your code.
Cocoa defines a string constant called NSFileContentsPboardType.
You're using a constant string with the *contents*
@"NSFileContentsPboardType". This is *not* the same thing. Nothing
says that the string constant must contain a string which exactly
matches its name. And in this case, it doesn't match. Use
NSFileContentsPboardType instead of @"NSFileContentsPboardType" and
you'll find your code will suddenly work. Any time the actual content
of a string constant is not documented, you *must* only use the
constant itself in your code, not what it contains (or what you think
it contains).
Mike
_______________________________________________
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