Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
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.
 
how then are you supposed to paste a nsmanagedobject?

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

Any idea why they changed the way pasteboards operate?

All I found was from here but it's fairly useless:
http://developer.apple.com/mac/library/releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_6.html
NSPasteboard: Support for multiple items and a more general and flexible API
 

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:
The writing methods available on Mac OS X v10.5 and earlier all operate on what is conceptually the first item on the pasteboard. They accept UTIs and pboard type strings. In a future release they may take only UTIs. On Mac OS X v10.6 and later, the writing methods such as setData:forType: still provide a convenient means of writing to the first pasteboard item, without having to create the first pasteboard item.

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. :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.