awakeFromUndo?
awakeFromUndo?
- Subject: awakeFromUndo?
- From: "Hamish Allan" <email@hidden>
- Date: Sun, 4 May 2008 16:39:44 +0100
I have a Cocoa app presenting a classic master-detail view of managed
objects, each of which represents a machine on a network and has a
string property "address". I also have a class which monitors the
status of a networked machine whose initialiser takes such an address.
Therefore in awakeFromInsert and awakeFromFetch in my NSManagedObject
subclass I add self as an observer for self's address property, and in
the observeValueForKeyPath:... method I set up a new or replacement
monitoring object. Conversely, in willTurnIntoFault I remove the
monitoring object and the observer.
This works fine as I add and remove items using my array controller,
but if I remove an item and then undo that removal, the object is
reinserted into the context, but without awaking either from insert or
from fetch. I am wondering where I should put my hook for adding the
address observer, or whether I should be doing something different
altogether.
Thanks,
Hamish
P.S. I have written the following workaround, but it relies on a private method:
// NSManagedObjectContextWorkaround.h
#import <Cocoa/Cocoa.h>
@interface NSManagedObjectContextWorkaround : NSManagedObjectContext
{
}
@end
@interface NSManagedObjectContext (PrivateNSManagedObjectContextWorkaround)
- (void)_undoDeletions:(id)object;
@end
// NSManagedObjectContextWorkaround.m
#import "NSManagedObjectContextWorkaround.h"
@implementation NSManagedObjectContextWorkaround
- (void)_undoDeletions:(id)deletions
{
[super _undoDeletions:deletions];
@try
{
for (NSManagedObject *deletion in [deletions objectAtIndex:0])
[deletion awakeFromFetch]; // treating this as a fetch works for my purposes
}
@catch (NSException *exception)
{
}
}
@end
_______________________________________________
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