copy & paste in Snowy (10.6)

Discussion in 'Mac Programming' started by MrFusion, Aug 10, 2010.

  1. MrFusion macrumors 6502a

    Jun 8, 2005
    In Snowy, Apple changed how to use the pasteboard.

    Rather than getting data from your objects, archiving it and placing it on the pasteboard, the data gets written directly to the pasteboard if your custom class implements the NSPasteboardWriting and NSPasteboardReading protocols.

    NSArray *objectsToCopy = <#An array of objects#>;
    BOOL OK = [pasteboard writeObjects:objectsToCopy];
    The NSPasteboardReading protocol has a method (initWithPasteboardPropertyList:eek:fType:) for creating a new instance from the pasted data, but also initWithCoder: is used.

    However, you are not supposed to used init methods for NSManagedObject's. NSManagedObject also doesn't implement the NSCoding protocol. Thus my question: how then are you supposed to paste a nsmanagedobject?

    Any idea why they changed the way pasteboards operate?

  2. kainjow Moderator emeritus


    Jun 15, 2000
    There are some docs that discuss this topic:

    All I found was from here but it's fairly useless:
  3. MrFusion thread starter macrumors 6502a

    Jun 8, 2005
    Thanks for the links. Making an array of dictionaries (one dictionary per managedObject) and placing it on the pasteboard was indeed the way to copy NSManagedObjects in 10.5 and below. This still is possible in 10.6 with setData:forType:

    From NSPasteBoard class reference:
    So this method only operates on the first item of the pasteboard, while pasteboards in 10.6 can place multiple items (one per copied object) on the pasteboard. The new pasteboard system, in my view, is a mixed system of old and new ways. The old way for managedObjects, the new way for anything else. Can't say I like it. :(

Share This Page