开发者

How to separate model and view with Core Data?

开发者 https://www.devze.com 2023-01-01 10:38 出处:网络
I have a subclass of UIView which draws itself based on data held in a corresponding model class, which is a subclass of NSManagedObject.

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 pro开发者_高级运维blem 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消