Re: Calling processPendingChanges from awakeFromInsert
Re: Calling processPendingChanges from awakeFromInsert
- Subject: Re: Calling processPendingChanges from awakeFromInsert
- From: Michael Burns <email@hidden>
- Date: Thu, 20 Sep 2007 17:07:36 -0400
The performSelector bit was part of what I thought might have been a
solution to my problem. Here's what I'm really trying to do:
This is an NSPersistentDocument based application. Every time a new
document is created, an entity called a "Project" is created which
stores all sorts of global data relevant to that document. The
awakeFromInsert from below is for another NSManagedObject
("WBObject") which is created through cocoa bindings as I explained.
The "Project" entity has a to-many relationship called "objects" and
the "WBObject" entity has a to-one relationship called "project".
All I am trying to do is set up that relationship when a new
"WBObject" object is created.
Does that make sense?
On Sep 20, 2007, at 4:59 PM, Jim Correia wrote:
On Sep 20, 2007, at 4:13 PM, Michael Burns wrote:
I'm having a strange problem while trying to set a value for an
NSManagedObject in its "awakeFromInsert" method. The code is as
follows:
- (void)awakeFromInsert
{
[super awakeFromInsert];
NSManagedObjectContext* moc = [self managedObjectContext];
// don't allow this new object to be undone
[moc processPendingChanges];
[[moc undoManager] disableUndoRegistration];
[self performSelector:@selector(setUniqueProject) withObject:nil
afterDelay:0];
// turn the undo manager back on
[moc processPendingChanges];
[[moc undoManager] enableUndoRegistration];
}
The object is inserted by pressing a button binded to an
NSArrayController who's set is binded to an NSTableView. The
problem is that when I run this code as is, it creates two
identical objects in the table view. If I comment out the two
[moc processPendingChanges] lines, the problem goes away but then
(of course) I can undo the actions in "setUniqueProject" and that
is not good.
As Tony mentioned, processPendingChanges inside of -awake<xxx> is a
bad idea.
But it is unclear to me from your code snippet what you are trying
to disable undo registration for in the first place?
You've disabled undo registration, scheduled a perform delayed
selector (in other words, do this later, not right now), then re-
enabled undo registration. It isn't clear to me what you intended
to do, but I think whatever it was, it isn't what your code is
doing :-).
Jim
_______________________________________________
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
Mike Burns
Production Associate/Audio Specialist
Modlin Center for the Arts
University of Richmond
Office - 804-287-6618
Cell - 804-370-4946
Fax - 804-287-6031
_______________________________________________
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