In an iOS application that I am refactoring, I am using Core Data as the main persistence layer. I am trying to refactor towards a proper MVC pattern. However, I have been trying to remove NSManagedObject* objects from the UI, because I believe the models should be what care about the persistence layer.
I am struggling to decide one way or another if I should allow the UI to retain an NSManagedObjectContext, or if the models should maintain a context for retrieving the information requested by the UI, then return a dumb object (not an NSManagedObject) to the the UI. With my experience, I am inclined to want to have the models know of all persistence to separate concerns, but I also struggle to justify that pattern.
Can someone help me to make sense of what I should do and why?
After much thought, reading, and other review, I have decided that it is acceptable for controllers to be aware of the context. The context can be used more or less as a model, and as long as the view logic is not aware of it, then it doesn’t violate MVC.
I personally would rather keep contexts under a service layer, and I do try to keep them underground, but having a UI managed object context comes with a great amount of convenience; just make sure you understand the cost.