Question

I will preface this by saying I am very new to the whole programming scene. Nonetheless, I am making some headway in my first OS X app, a simple "Paint" style application. However, after reading the document-based programming guide, I am left with a few questions.

My current setup is that I pass variables "through" my custom objects to reach it's destination. e.g. I have my custom view, which creates a custom controller and passes a pointer to itself to it. The controller then creates a data model and passes a reference to the view to the data object. But then if an higher-up object needs that data, I need to have a system of methods and notifications to make it come back around. Also, it's becoming hard to make sure the data in the variables is in the right state as more objects point to it.

I've wanted to create a more horizontal setup, but I have a problem: how do I get the data collected by an NSView's NSResponder methods into a data object that's owned (is that the right term?) by a higher level controller? This diagram from the document SDK guide that I annotated illustrates my issue with the recommended setup: enter image description here

I know I'm doing a lot of things wrong, but I'm having trouble figuring out how to do it the "right" way. Could somebody tell me how I'm supposed to encapsulate my input from a view in a data object properly?

Was it helpful?

Solution

I am not sure I understand your question correctly, but I guess the answer is usually: You don't do that.

The controller is notified when the view gets input. This might be by delegation or observation but in most cases through target-action. The responder chain is not in focus at this point, it works in the background.

The controller is also responsible for making all the changes to the model, which it instantiates and handles.

In your example NSDocument will do some of these data model things for you, but NSDocument is not used in every application.

The other direction usually works through outlets, where the controller fills in all data the user-interface is likely to need. In an NSDocument based application the subclass of NSDocument will usually take the part of the controller here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top