NSPasteboardItem issues

  • I'm trying to convert code to use the new pasteboard methods, and having a
    few issues.  For private types, I need to use NSPasteboardItem because the
    read/write protocols don't work for managed objects.  (readObjects
    automatically uses NSKeyedUnarchiver and I use a subclass to provide the
    moc.)  The following claims success in writing to the general pasteboard,
    but the paste handler is not seeing the NSPasteboardItem.  The property list
    is an array of data.

    //    Copy
    - (void) putShapes:(NSArray*)shapes ontoPasteboard:(NSPasteboard*)pboard {
        [pboard clearContents];
        NSPasteboardItem *pbItem = [[NSPasteboardItem alloc] init];
        [pbItem setPropertyList:[self propListForShapes:shapes]
    forType:RTPShapesType];
        NSArray *objArray = [NSArray arrayWithObject:pbItem];
        BOOL success = [pboard writeObjects:objArray];
        //  success = YES;
    }

    //    Paste
        classArray = [NSArray arrayWithObject:[NSPasteboardItem class]];
        if([pboard canReadObjectForClasses:classArray options:dict]) {
        //    This fails.  *dict = [NSDictionary dictionary]

    Is there anything obvious I'm missing?

    Another question -- Dragging in a color chip provides both an NSColor and an
    NSPasteboardItem.  Given the first, what use is the latter?
  • Invariably happens.  I hesitate and agonize over whether to hit the ³send²
    button, then promptly discover the solution.  Apparently, I need to be using
    ³canReadItemWithDataConformingTpTypes² instead.  However, it is still a
    mystery to me as to why the other failed.

    On 6/20/12 12:28 PM, "Gordon Apple" <ga...> wrote:

    > I'm trying to convert code to use the new pasteboard methods, and having a few
    > issues.  For private types, I need to use NSPasteboardItem because the
    > read/write protocols don't work for managed objects.  (readObjects
    > automatically uses NSKeyedUnarchiver and I use a subclass to provide the moc.)
    > The following claims success in writing to the general pasteboard, but the
    > paste handler is not seeing the NSPasteboardItem.  The property list is an
    > array of data.
    >
    > //    Copy
    > - (void) putShapes:(NSArray*)shapes ontoPasteboard:(NSPasteboard*)pboard {
    > [pboard clearContents];
    > NSPasteboardItem *pbItem = [[NSPasteboardItem alloc] init];
    > [pbItem setPropertyList:[self propListForShapes:shapes]
    > forType:RTPShapesType];
    > NSArray *objArray = [NSArray arrayWithObject:pbItem];
    > BOOL success = [pboard writeObjects:objArray];
    > //  success = YES;
    > }
    >
    > //    Paste
    > classArray = [NSArray arrayWithObject:[NSPasteboardItem class]];
    > if([pboard canReadObjectForClasses:classArray options:dict]) {
    > //    This fails.  *dict = [NSDictionary dictionary]
    >
    > Is there anything obvious I'm missing?
    >
    > Another question -- Dragging in a color chip provides both an NSColor and an
    > NSPasteboardItem.  Given the first, what use is the latter?
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today