• 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: Drag From iTunes in NSView just like iWeb did
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drag From iTunes in NSView just like iWeb did


  • Subject: Re: Drag From iTunes in NSView just like iWeb did
  • From: Fritz Anderson <email@hidden>
  • Date: Thu, 28 Sep 2006 12:07:19 -0500

I can offer some comments, though I don't know how far they may bring you toward your goal. Much of the work you will have to do yourself.

On Sep 28, 2006, at 2:20 AM, Nishant Yede wrote:

in init method i wrote
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];


- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *paste = [sender draggingPasteboard];
NSArray *types = [NSArray arrayWithObjects:NSFilenamesPboardType,nil];
NSString *desiredType = [paste availableTypeFromArray:types];
NSData *carriedData = [paste dataForType:desiredType];

The only possible values for desiredType are NSFilenamesPboardType (if it's present) or nil (if it's not). What are you doing about the possibility that desiredType is nil?


NSArray *urlArray = [paste propertyListForType:NSURLPboardType];

Elsewhere you expressed interest in the list-of-filenames pasteboard type (which is an array, a property-list type). Now you are pulling something else, a single URL, out of the pasteboard (assuming there is one), and casting it to an array. Why?


Aside from the fact that urlArray would not be an array, what are you doing about its possibly being nil?

NSString *data = [[NSString alloc] initWithString:[urlArray objectAtIndex:0]];

If urlArray is a URL, it doesn't recognize objectAtIndex:, a diagnostic will be printed to that effect, and execution of this method will be abandoned here. If it's nil, it will be passed with the initWithString: message, which is documented not to tolerate a nil parameter, so this is a crasher, or causes an exception, which again would abandon the execution of this method.


"data" is a name an experienced Cocoa programmer would not choose for a string. Strings and data are concepts one would be at pains to keep separate.

Is there some reason you want to allocate (but never release) a new NSString with content identical to the NSString you assume you'd get from objectAtIndex: ?

And, if you aren't yet sure what pasteboard type you should look for, why has it not helped you to put a breakpoint in this function and type "po [paste types]" in the GDB console? I'll admit to having been baffled at pasteboards more than once; I'll probably be baffled the next time. But stepping, interrogating the pasteboard, and examining the method results always pulled me through.

if (nil == carriedData)
{
NSRunAlertPanel(@"Paste Error", @"Sorry, but the past operation failed", nil, nil, nil);

Even if you're the only one to see them, it's worth the very small trouble to make your error messages informative. For instance, @"Could not get data for expected pasteboard type '%@'", nil, nil, nil, desiredType. This is still very rude to a user, but you might find it useful.


        return NO;
    }
    else
    {
		data = [data substringFromIndex:16];

Eh? What is it about "data" that leads you to expect that you can drop the first 16 characters and get something useful? I can't think of a class of URLs for which that would be true.


		NSLog(data);
		if([musicFileType containsObject:[data pathExtension]])
...
    return YES;
}
   Please check this code and reply what i did wrong in this.

Sigh.

Life is hard, but surely your time would be better spent in reading the documentation, thus acquiring the skills you need to see for yourself what you did wrong? Or in stepping through you code with a debugger, thus giving you the information you need to understand what you did wrong?

	-- F

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Drag From iTunes in NSView just like iWeb did (From: "Nishant Yede" <email@hidden>)

  • Prev by Date: Re: Conversion of =E? string
  • Next by Date: Re: Conversion of =E? string
  • Previous by thread: Drag From iTunes in NSView just like iWeb did
  • Next by thread: Re: Drag From iTunes in NSView just like iWeb did
  • Index(es):
    • Date
    • Thread