• 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
Core Data KVO with To-Many Relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data KVO with To-Many Relationships


  • Subject: Core Data KVO with To-Many Relationships
  • From: John McIntosh <email@hidden>
  • Date: Mon, 5 Oct 2009 13:18:38 -0500

Hi all.
I am working on a Core Data application which contains an entity that
needs to be notified of changes in entities that it has a relationship
to. Let's talk about this in terms of Apple's example with Departments
and Employees. As described here
(http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html)
they talk about the example where each Department has a "totalSalary"
attribute and each Employee has a "salary" attribute.

In regards to Core Data, the documentation linked above says this:
"If you're using Core Data, you can register the parent with the
application's notification center as an observer of its managed object
context. The parent should respond to relevant change notifications
posted by the children in a manner similar to that for key-value
observing."

I assume this means that something similar to the code posted
previously in the article should be done. I understand the statement
conceptually, but do not know how to go about implementing it. Here is
my start in the Department entity.

- (void) awakeFromInsert{
     [[NSNotificationCenter defaultCenter]    addObserver:self
selector:@selector(methodToCallOnNotification:)   name:???
object:managedObjectContext];
}

If this is the correct start, what should happen in methodToCallOnNotification?
Do I need to remove each Department entity from being an observer when
it is deleted?
What else do I need to be sure to do upon Department or Employee
creation or deletion?

Thank you,

John
_______________________________________________

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

  • Follow-Ups:
    • Re: Core Data KVO with To-Many Relationships
      • From: John McIntosh <email@hidden>
  • Prev by Date: Objective Lua
  • Next by Date: Problems calling a method from an IB-created instance...
  • Previous by thread: Objective Lua
  • Next by thread: Re: Core Data KVO with To-Many Relationships
  • Index(es):
    • Date
    • Thread