It's a duplicate of this question.
I was having trouble grasping some Cocoa fundementals (in particular, Controllers and Delegates), so I decided to complete a basic tutorial. I found a 'Your First Mac Application' and all went well until "Where To Next" stage. Here's a bunch of presumably basic things that I don't understand about it:
>
- "Create a new controller class, and move for managing the track and the user interface from the application delegate to this new class."
...What's the point in creating a separate controller class? I get MVC pattern and used it in the past, I just can't figure out the place for separate Controller and Delegate there.
- "Create an instance of the controller class in the nib file, and make appropriate connections to and from it, rather than to and from the application delegate."
...Prior to that point I just thought that I just create a subclass of NSWindowController and then declare in .xib file that the window should be the object of this class. Now I'm consused. What class should the controller be? What interfaces (sorry, protocols) should it conform? If it's just a class that I point outlets to, then once again — what's the difference from the Delegate that I already have?
- "Add a connection from the application delegate to the new controller object. When the application has finished launching, the application delegate should send a message to the controller to display the window."
...What's the message? The closest thing I found is showWindow: message in NSWindowController class, but when I write this:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[trackController showWindow:self];
}
in applicationDidFinishLaunching method of AppDelegate, it shows error "Receiver type 'TrackController' for instance message is a forward declaration', and I just can't understand what does it mean.
More than that — why should I send a message to show this window at all, if this window shows without any code at that I create all, in a blank project? Maybe I should somehow turn off this default behavior and create an instance of this window myself?