july 13
This post helped me understand that when using custom accessors the system will not complain. But the lack of complaint does not mean that things will work correctly.
"CoreData NSManagedObjectContexts use Key-Value Observing to track changes to the in-memory objects they own. They do this through the normal KVO mechanisms, though in some cases they leverage the runtime in unusual ways to accomplish this (which is why CoreData does not always play well with Swift).According to the documentation, NSManagedObject subclasses do not automatically send KVO notifications for modeled properties. This may no longer be accurate, and is easy to verify if you are interested. For the most part it is irrelevant - if your application is interested in key value observing notifications for objects you control implement+automaticallyNotifiesObserversOf<Key> to emit automatic key value notifications for synthesized accessors.If you implement your own accessor methods for NSManagedObject properties (not...really...recommended...) you MUST ensure that the key value observing notifications methods are called at the appropriate times (willChangeValueForKey:/didChangeValueForKey:) in addition to the relevant CoreData specific methods (willAccessValueForKey:/didAccessValueForKey:). If you do not do so the internals of CoreData will not reliably track changes to those properties. And that would be bad.When a managed object instance changes the context that owns it sees the change via KVO and adds it to the internal change tracking of the context. These changes are coalesced, and when the context is saved the changes are committed.” -quellish
No comments:
Post a Comment