• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSPasteboard issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPasteboard issue


  • Subject: NSPasteboard issue
  • From: Michael Swan <email@hidden>
  • Date: Thu, 26 Mar 2009 19:53:04 -0400

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];
// 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 (email@hidden)

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 email@hidden


  • Follow-Ups:
    • Re: NSPasteboard issue
      • From: Michael Ash <email@hidden>
  • Prev by Date: Advice on the suitability of Core Animation in this situation
  • Next by Date: NSFileManager: can't set group ID on 10.4
  • Previous by thread: Advice on the suitability of Core Animation in this situation
  • Next by thread: Re: NSPasteboard issue
  • Index(es):
    • Date
    • Thread