copy & paste in Snowy (10.6)

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

  1. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    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.

    Code:
    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?

    Thanks.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    There are some docs that discuss this topic:
    http://developer.apple.com/mac/libr...entTutorial/05_CopyAndPaste/copyAndPaste.html
    http://developer.apple.com/mac/libr...Os.html#//apple_ref/doc/uid/TP40001803-213600

    All I found was from here but it's fairly useless:
    http://developer.apple.com/mac/library/releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_6.html
     
  3. MrFusion thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #3
    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