Ah, it is interesting that you say this, because now suddenly I realize that 
the problem might be related to bindings (although I'm not sure).

Please follow these simple steps to make a very simple test app that 
demonstrates my issue:


1) Create a new "Core Data Application" project in Xcode.
2) Add an Employee entity with the 'name' (String) attribute.
3) Open the XIB file, and onto the window add a table view with one column and 
two buttons called "Add" and "Remove".
4) Add an NSArrayController into the XIB. Bind it to the app delegate's 
managedObjectContext and set the Employee entity and "Prepares content" as 
usual.
5) Bind the table column to the array controller's arrangedObjects.name as 
usual.
6) Connect the Add and Remove buttons to the NSArrayController's add: and 
remove: methods respectively.
7) Back in the code, paste the following into the app delegate's source file:



- (void)awakeFromNib
{
  NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
  [nc addObserver:self
         selector:@selector(contextChanged:)
             name:NSManagedObjectContextObjectsDidChangeNotification
           object:[self managedObjectContext]];
}

- (void)contextChanged:(NSNotification *)note
{
  NSSet *inserted = [[note userInfo] objectForKey:NSInsertedObjectsKey];
  NSSet *updated = [[note userInfo] objectForKey:NSUpdatedObjectsKey];
  NSSet *deleted = [[note userInfo] objectForKey:NSDeletedObjectsKey];
    NSLog(@"contextChanged. inserted %d. updated %d. deleted %d.",
  [inserted count],[updated count],[deleted count]);
}



8) Play with this app. You will see that the notifications are properly getting 
sent.
9) Now add "[[[self managedObjectContext] undoManager] 
disableUndoRegistration];" to the top of awakeFromNib.
10) As you now play with the app, you will notice that the notification is NOT 
getting sent except when the app quits (and the context saves).



Can you guys help me analyze why, when using bindings like this, 
NSManagedObjectContextObjectsDidChangeNotification is not getting sent anymore 
when undo is disabled?



----------------------------------------
> From: mmalc_li...@me.com
> Date: Sat, 1 Aug 2009 13:58:07 -0700
> To: cocoa-dev@lists.apple.com
> Subject: Re: Disabling Undo in Core Data
>
>
> On Aug 1, 2009, at 5:11 AM, Squ Aire wrote:
>
>> 1) In awakeFromNib, call either [[self managedObjectContext]
>> setUndoManager:nil]; or [[[self managedObjectContext]
>> undoManager] disableUndoRegistration]; This certainly works, but
>> the problem with this is that the
>> NSManagedObjectContextObjectsDidChangeNotification will stop being
>> sent when the context changes!
>>
> It's not clear why you make this assertion? A simple test shows this
> is not the case...
>
> Did you register for
> NSManagedObjectContextObjectsDidChangeNotification or
> @"NSManagedObjectContextObjectsDidChangeNotification"?
>
> mmalc



_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to