• 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
Re: Implementing Undo for a Cut operation, against an NSManagedObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implementing Undo for a Cut operation, against an NSManagedObject


  • Subject: Re: Implementing Undo for a Cut operation, against an NSManagedObject
  • From: Jim Correia <email@hidden>
  • Date: Mon, 26 Jun 2006 11:42:06 -0400

On Jun 24, 2006, at 7:51 AM, Neil Clayton wrote:

Hi,
I'd like to be able to nicely undo a cut operation, for a managed coredata object.


My initial idea was something like this (where Preset is the managed object):

- (void) addPresetBack:(Preset*)preset {
	[presetsController insert:preset];
}

- (IBAction) cut:(id)sender {
	Preset *preset = [presetsController selectedObject];
	[self copy:self]; // store some interesting data in pasteboard
	NSUndoManager *undo = [self undoManager];
	[[undo prepareWithInvocationTarget:self] addPresetBack:preset];
	if(![undo isUndoing]) {
		[undo setActionName:NSLocalizedString(@"Cut", @"Cut")];
	}
	[presetsController removeObject:preset];
}

But I'm finding (probably quite sensible) that the preset is dead/ empty once I get back to addPresetBack. This makes sense, since removing it from the NSArrayController probably causes the object to be deleted from the current DB. Thus, when Undo is called, I end up inserting a blank object.

Forgetting about CoreData for the moment, that code is wrong. You typically need to register the inverse of your action with the undo manager. Your code is not doing this.


What's the recommended way to handle cut/undo style operations with CoreData?

CoreData is an object-graph management and persistence framework.

It will automatically manage undo operations on your object graph.

Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Implementing Undo for a Cut operation, against an NSManagedObject (From: Neil Clayton <email@hidden>)

  • Prev by Date: Re: objectForKey:self
  • Next by Date: Re: objectForKey:self
  • Previous by thread: Implementing Undo for a Cut operation, against an NSManagedObject
  • Next by thread: NSTextView and NSWindowController
  • Index(es):
    • Date
    • Thread