In my project, which is written entirely with Core Data and bindings, I have two text fields which contain float values. I want to make a third text field that is the first field divided by the second. What is the best way to go about this using Core Data? Should I make a custom accessor for the third field?
Share
Make a method -thirdValue in your NSManagedObject subclass that does the calculation:
and then +keyPathsForValuesAffectingValueForKey for the class:
this sets up thirdValue to be dependent on value1 and value2. Whenever value1 or value2 change, there will also be a KVO notification for thirdValue. So if you have a field that binds to it, the field will display the new calculated value. It’s a a handy trick when you need to display a key who’s value is dependent on other keys.