Hi.

Is this any better? See bewlo, and in addition: Did it work? It shouldn't have worked :-/

On NSManagedObject side:

According to Apple the initWithEntity should not be overridden (http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdCreateMOs.html )
"
you are discouraged from overriding initWithEntity:insertIntoManagedObjectContext:; instead, Core Data provides several other means of initializing values—these are described in “Object Life-Cycle—Initialization and Deallocation.”"

The blue links to: “Object Life-Cycle—Initialization and Deallocation.”

So add it to awakeFromInsert or / and awakefromFetch

On observee side:

[performSelector...] can't work and you should get a warning when compiling. Take these warnings seriously and try to understand them, because they exist for a good reason!

[self performSele...] for example would work, even so [self selectorname] is more simple to read.

You will be in need to remove the observer again - that depends on different aspects. I am referring again to the mailing list archive.

Volker

Am 07.10.2009 um 17:55 schrieb Joshua Garnham:

Hi,

Here's what I have done, I have subcalssed NSManagedObject and added the following code …

- (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:(NSManagedObjectContext *)context { [self addObserver:[NSApp delegate] forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
}

… And in my App Delegate …

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context {
    [performSelector:@selector(doSomething:)];
}

Is this any better?
_______________________________________________

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