I have an attribute in a Core Data Managed Object that I’m trying to update dependent on another attribute.
How can I implement a method that is called every time the original attribute is changed?
awakeFromInsert and awakeFromFetch obviously won’t work.
I’ve seen keyPathsForValuesAffectingValueForKey but I don’t really understand how I could use it.
Thanks a bunch
You’re on the right track. Let’s say you’ve got two attributes:
foo, andbar, withbarbeing calculated based onfoo. For this, you need to implement the+keyPathsForValuesAffectingBarmethod:Now, every time
foochanges, any objects bound tobarwill update themselves.Obviously, this wont do much good if you’re caching the value of
bar, since you need to actually recalculate and recache it. However, unless you’re doing some seriously hardcore calculations to determinebar, you’re really better off just calculatingbarevery time the-barmethod is called.