NSPasteboard issue

Hello all,
I am working on copy/paste in Core Data and have been following the NSPersistentDocument Core Data Tutorial tutorial from
I am having a problem with the pasteboard in that I can't seem to get data out of it once I leave the copy: method. All of the data is correct all through the copy method (I even pull it back off the pasteboard to check it, and all is fine there) as soon as I move to the paste: method I get NULL data, looked around on Google for ideas but none so far. The relevant code is below, any ideas are welcome:

#import "MyDocument.h"
NSString *MSSalesPBoardType = @"MSSalesPBoardType";

@implementation MyDocument

- (void) copy:(id *) sender
// removed selection code correct data exists in this NSLog statement
NSLog(@"copyObjectsArray = %@.", [copyObjectsArray description]);

NSPasteboard *generalPasteboard = [NSPasteboard generalPasteboard];
[generalPasteboard declareTypes:[NSArray arrayWithObjects:MSSalesPBoardType, NSStringPboardType, nil] owner:self];
NSData *copyData = [NSKeyedArchiver archivedDataWithRootObject:copyObjectsArray];
NSArray *salesArray = [NSKeyedUnarchiver unarchiveObjectWithData:copyData];
// Here the data is intact
NSLog(@"salesArray = %@.", [salesArray description]);
NSLog(@"copyData = %@.", [copyData description]);
[generalPasteboard setData:copyData forType:MSSalesPBoardType];
[generalPasteboard setString:[copyStringsArray componentsJoinedByString:@"\n"] forType:NSStringPboardType];
NSData *data = [generalPasteboard dataForType:MSSalesPBoardType];<...

br> // Here the data is still intact and matches the above description of copyData
NSLog(@"data = %@.", [data description]);

- (void) paste:(id *) sender
NSPasteboard *generalPasteboard = [NSPasteboard generalPasteboard];
NSData *data = [generalPasteboard dataForType:MSSalesPBoardType];
if (data = nil)
// Here data = NULL
NSLog(@"data = %@.", [data description]);
NSArray *salesArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
// ... method continues...


Mike Swan
"Change itself is not painful it is resistance to change that causes pain."


Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)

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 maillists@xxxxxxxxx