views:

43

answers:

1

I have a subclass of UIView which draws itself based on data held in a corresponding model class, which is a subclass of NSManagedObject.

The problem is, some fields in the data model (e.g. the position of the view) are already held in the view (i.e. the frame property in this case). I then have a data duplication/synchronization problem to solve.

To complicate matters further, the view needs to update in response to changes made to the data model and the data model needs to be updated in responses made to the view (e.g. the user dragging it to a new location).

What's the best way to solve this? Using KVO and references in both directions?

Or is there a better approach?

+1  A: 

Given your constraints, you'll probably have to use KVO on both your UIView and your NSManagedObject, although you'll probably want to put that code your view controller.

Shaggy Frog
Many thanks - that was the solution I was leaning towards, but needed some reassurance I was on the right track.
Andrew Ebling