Re: NSValue, Drag & Drop
Re: NSValue, Drag & Drop
- Subject: Re: NSValue, Drag & Drop
- From: Brian Webster <email@hidden>
- Date: Sun, 9 Nov 2003 17:44:03 -0600
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
_______________________________________________
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.