NSPasteboard issue



Hello all,
I am working on copy/paste in Core Data and have been following the NSPersistentDocument Core Data Tutorial tutorial from
http://developer.apple.com/documentation/Cocoa/Conceptual/NSPersistentDocumentTutorial/05_CopyAndPaste/copyAndPaste.html
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)
{
return;
}
// Here data = NULL
NSLog(@"data = %@.", [data description]);
NSArray *salesArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
// ... method continues...

}

Thanks,
Mike Swan
http://www.michaelsswan.com
"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:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to maillists@xxxxxxxxx



Privacy