That's the kind of thing I'm trying to avoid. There's no need to do that, since the drag is only within my app. I just want the drag receiver to have access to a *point* to the object, not a new copy of the object.

On Oct 14, 2009, at 17:34:06, Kiel Gillard wrote:

You could archive and unarchive your object as data using NSKeyedArchiver and NSKeyedUnarchiver.

<http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Archiving/Tasks/creating.html#//apple_ref/doc/uid/20000949 > <http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Archiving/Tasks/codingobjects.html#//apple_ref/doc/uid/20000948 >

Kiel

On 15/10/2009, at 11:21 AM, Rick Mann wrote:

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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/kiel.gillard%40gmail.com

This email sent to kiel.gill...@gmail.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to