• 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: NSValue, Drag & Drop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSValue, Drag & Drop


  • Subject: Re: NSValue, Drag & Drop
  • From: Duncan Oliver <email@hidden>
  • Date: Mon, 10 Nov 2003 10:20:43 -0600

Thanks. I had forgotten all about the restrictions on making property lists. on attempting to archive the NSValue, the console tells me that I can't archive the value, I guess I'll have to find another way to point to the value during the drop. Thanks again.

On Nov 9, 2003, at 5:44 PM, Brian Webster wrote:

NSValue is not supported as a type for making property lists. You need to use only NSDictionary, NSArray, NSNumber, NSData, and NSString if you want to use setPropertyList:forType:. One other way you could do it though would be to serialize the array yourself using NSArchiver and then just write the resulting NSData to the pasteboard.

On Nov 9, 2003, at 1:43 PM, Duncan Oliver wrote:

I have a outlineView that I want to enable internal dragging and dropping in. I've been trying to write NSValue objects to the dragging Pasteboard and retrieve those values in the acceptDrop method. I can write the values to the pasteboard fine, but when I try to make an array using propertyListForType, nothing is written. When making a mutable array (using PropertyListSerialization) the error string says that there are too few bytes.

Here's the code:

- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
{
NSMutableArray *collectionObjectArray = [NSMutableArray array];
NSEnumerator *enumerator = [items objectEnumerator];
NSMutableDictionary *object;
BOOL success;

while (object = [enumerator nextObject])
{
[collectionObjectArray addObject:[NSValue valueWithPointer:object]];
}

//Set dragged objects
[pboard declareTypes:[NSArray arrayWithObjects:@"CollectionObjectPboardType", nil] owner:nil];
success = ([pboard setPropertyList:collectionObjectArray
forType:@"CollectionObjectPboardType"]);
return success;
}

- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
{
NSArray *array;
NSEnumerator *enumerator;
NSValue *objectPointer;

//Make mutable array from dragged object array
array = [[info draggingPasteboard] propertyListForType:@"CollectionObjectPboardType"];
NSLog([[NSNumber numberWithInt:[array count]] stringValue]);
}

The log returns a count of 0:

Here's the initialization code using NSPropertyListSerialization:

{
format = nil;

array = [NSPropertyListSerialization propertyListFromData:[[info draggingPasteboard] dataForType:@"CollectionObjectPboardType"]
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:format
errorDescription:&error];

NSLog(error);
}

This is where log returns the too few bytes error.

Does anyone have an idea what I've done wrong? I'm using Xcode 1.0 on Mac OS X 10.3. Thanks.

Duncan Oliver
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster


Duncan Oliver
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSValue, Drag & Drop (From: Duncan Oliver <email@hidden>)
 >Re: NSValue, Drag & Drop (From: Brian Webster <email@hidden>)

  • Prev by Date: How to make Array of NSString
  • Next by Date: Re: drag and drop in same app
  • Previous by thread: Re: NSValue, Drag & Drop
  • Next by thread: Re: NSValue, Drag & Drop
  • Index(es):
    • Date
    • Thread