• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Triggering a Method when a Core Data Property is Altered.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Triggering a Method when a Core Data Property is Altered.


  • Subject: Re: Triggering a Method when a Core Data Property is Altered.
  • From: Volker in Lists <email@hidden>
  • Date: Wed, 7 Oct 2009 18:43:11 +0200

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 (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


References: 
 >Triggering a Method when a Core Data Property is Altered. (From: Joshua Garnham <email@hidden>)
 >Re: Triggering a Method when a Core Data Property is Altered. (From: Volker in Lists <email@hidden>)
 >Re: Triggering a Method when a Core Data Property is Altered. (From: Volker in Lists <email@hidden>)
 >Re: Triggering a Method when a Core Data Property is Altered. (From: Volker in Lists <email@hidden>)

  • Prev by Date: Re: Problem using filewrappers under snow leopard
  • Next by Date: Re: Strange Core Data problem after upgrade
  • Previous by thread: Re: Triggering a Method when a Core Data Property is Altered.
  • Next by thread: Re: Triggering a Method when a Core Data Property is Altered.
  • Index(es):
    • Date
    • Thread