Can I make custom pasteboard type for an object reference?
Can I make custom pasteboard type for an object reference?
- Subject: Can I make custom pasteboard type for an object reference?
- From: Rick Mann <email@hidden>
- Date: Wed, 14 Oct 2009 17:21:07 -0700
I'm trying to implement a library like Interface Builder's. When the
user drags an item out of the library and onto one of my custom views,
it should instantiate an object and place it in the view accordingly.
I'm trying to implement the drag by writing to the pasteboard an
NSData object I create that contains a reference to the object, like so:
- (BOOL)
collectionView: (NSCollectionView*) inCollectionView
writeItemsAtIndexes: (NSIndexSet*) inIndices
toPasteboard: (NSPasteboard*) inPasteboard
{
MyObject* foo = self.myFoo;
if (foo != nil)
{
[inPasteboard declareTypes: [NSArray arrayWithObject:
kUTIMyObjectRef] owner: nil];
[inPasteboard writeObjects: [NSArray arrayWithObject: plugIn]];
return YES;
}
return NO;
}
In MyObject:
- (NSArray*)
writableTypesForPasteboard: (NSPasteboard*) inPasteboard
{
static NSArray* types = nil;
if (types == nil)
{
types = [NSArray arrayWithObjects: kUTIMyObjectRef, nil];
}
return types;
}
- (id)
pasteboardPropertyListForType: (NSString*) inType
{
if ([inType isEqualToString: kUTIMyObjectRef])
{
NSMutableData* data = [NSMutableData data];
[data appendBytes: &self length: sizeof (self)];
return data;
}
return nil;
}
+ (NSArray*)
readableTypesForPasteboard: (NSPasteboard*) inPasteboard
{
static NSArray* types = nil;
if (types == nil)
{
types = [NSArray arrayWithObjects: kUTIMyObjectRef, nil];
}
return types;
}
But nowhere do I see a way to turn that NSData into an object
reference, and I'm pretty sure I'm not implementing
pasteboardPropertyListForType: correctly, anyway (I mimicked what I
saw in the docs).
Am I just going about this all the wrong way?
TIA,
Rick
_______________________________________________
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