• 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
Can I make custom pasteboard type for an object reference?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Can I make custom pasteboard type for an object reference?
      • From: Michael Ash <email@hidden>
    • Re: Can I make custom pasteboard type for an object reference?
      • From: Timothy Stafford Larkin <email@hidden>
    • Re: Can I make custom pasteboard type for an object reference?
      • From: mmalc Crawford <email@hidden>
    • Re: Can I make custom pasteboard type for an object reference?
      • From: Kiel Gillard <email@hidden>
  • Prev by Date: Re: SelectedRowIndexes
  • Next by Date: Re: Can I make custom pasteboard type for an object reference?
  • Previous by thread: Re: [SOLVED] Re: Help with NSURLConnection memory fault
  • Next by thread: Re: Can I make custom pasteboard type for an object reference?
  • Index(es):
    • Date
    • Thread