• 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: Observing Core Data model changes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Observing Core Data model changes


  • Subject: Re: Observing Core Data model changes
  • From: Matthew Firlik <email@hidden>
  • Date: Sat, 22 Apr 2006 22:17:11 -0700


On Apr 22, 2006, at 5:19 PM, Andres wrote:

I am working with a Core Data document application and I am trying to find a way to track all the changes made to managed objects but from a non managed class. This class should know about changes to properties, object creation, etc. I am new to Cocoa and after checking the documentation I just can't find a "supported" way of receiving this "events". So far I have come with a couple solutions but none of them are very pleasant:

1. Use notification center and add code to every managed object in order to send notifications about the changes
2. In each awakeFromInsert register a singleton for kv observing of "self"


I hope there is a better way to do it, that is why I am asking for a little orientation here.

Your subject line is a little misleading, in that you are really interested in object (instance) changes, not changes to the model (usually meaning the managed object model.) But in any case, your idea of using notifications will work -- and Core Data does most of the heavy lifting for you. NSManagedObjectContext provides two notifications that can serve you, depending on the scope/timing of changes you are interested in. You can receive notifications when the values of properties of *any* object in the context are changed, or just when a managed object context completes a save operation (so, once the changes are persisted into the store.)


These notifications are:

	NSManagedObjectContextObjectsDidChangeNotification
	NSManagedObjectContextDidSaveNotification

For more information, see the bottom section of the API reference at:

	http://developer.apple.com/documentation/Cocoa/Reference/CoreData_ObjC/Classes/NSManagedObjectContext_index.html

- matthew



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Observing Core Data model changes
      • From: Andres <email@hidden>
References: 
 >Observing Core Data model changes (From: Andres <email@hidden>)

  • Prev by Date: Re: Keys of the kingdom
  • Next by Date: Re: Observing Core Data model changes
  • Previous by thread: Observing Core Data model changes
  • Next by thread: Re: Observing Core Data model changes
  • Index(es):
    • Date
    • Thread