Re: grouping undo across method calls in CoreData
Re: grouping undo across method calls in CoreData
- Subject: Re: grouping undo across method calls in CoreData
- From: Quincey Morris <email@hidden>
- Date: Mon, 5 Oct 2009 10:08:04 -0700
On Oct 5, 2009, at 06:10, Jim Thomason wrote:
I've got a CoreData document based application, and I'm trying to undo
my object creation in a single step.
Here's the issue - I'm storing an ordered index on my entities so I
can keep track of the order of creation. To do this, upon object
creation, I yank out the highest order parameter for my entity, add 1
to it, and use it to set up my ordered column. But the issue is, in
order to do this and make it work well, I have to put the code to
create the ordered column in a separate selector that I hit using
performSelector:, as such:
-(void) awakeFromInsert {
[super awakeFromInsert];
[self performSelector:@selector(createOrder:) withObject:nil
afterDelay:0];
}
-(void) createOrder {
int highOrderIndex = [self getHighestIndexSomeHow];
[self setValue:[NSNumber numberWithInt:highOrderIndex]
forKey:@"ordered"];
}
You might consider a different approach. Instead of trying to bend
Core Data undo to your will, you might be able to finesse the
situation by preparing all the information for your object creation
*first*, then creating the object in a single event cycle (and hence
undo action).
Thus, calculate the highest index first, which may involve zero or one
or any number of "performSelector...afterDelay" calls, and create the
object when you're done.
Alternately, you might pre-calculate the *next* highest index *after*
the creation of a new object.
In any scenario (including the one you originally described), there
does seem to be a theoretical possibility that a new request to create
an object may arrive in the middle of your sequence of delayed
selectors. You'd probably want to consider how to handle that situation.
_______________________________________________
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