How to see how many files in draggingPasteboard?

304 Views Asked by At

I have a drag operation that only allows to drag a single file, and I want to capture this on "draggingEntered" like so:

- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
  if ([[sender draggingPasteboard] count]] == 1) {
    return NSDragOperationCopy;
  }
  else {
    return NSDragOperationNone;
  }
}

But count is not valid method or property, but I can't figure out what to replace it with, so which is the best way to see how many items there are on the draggingPasteboard? Should I get the array of filenames on the draggingPasteboard using something like propertyListForType: NSFilenamsPboardType, and then get the index of that, or is there a more clever way to do this?

1

There are 1 best solutions below

0
On BEST ANSWER

If You want to use count You need to use pasteboardItems which is items array who response to count.

It can be done like this:

- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {

    if([[[sender draggingPasteboard] pasteboardItems] count] == 1) {
        return NSDragOperationCopy;
    }
    else {
        return NSDragOperationNone;
    }
}