Challenge Question - Why add the Controller?


#1

As an aside the name of this forum section is currently taget/action … I believe you need to buy an ‘r’ :wink:

In the challenge you tell us to setup a Controller. It is not hard to do per se…

  • New Objective C class (CountCharsController)
  • Add an Object to the XIB and set the class to this class
  • Add the outlets and actions to the controller

…my question is why did we not do that for SpeakLine if this is considered “proper” project construction. I could easily add the outlets and actions to the AppDelegate as we did in the chapter.

Just curious why we did the challenge differently.

Thank you in advance for your reply.

P.S. Really good book so far!


#2

Thanks for the tip on the forum name – fixed! :slight_smile:

As to your question on the controller object: part of the reason we suggest creating a controller object for the challenge is to get you to practice creating controller objects in the XIB. In the exercise for the chapter we put everything in the app delegate for simplicity.

As far as what’s more proper, in most projects your app controller will also be the app delegate. As we try to emphasize in Chapter 12, however, in a mature application each window will have its own controller (a window controller). Using the separate controller object here is a small step in that direction, and in thinking about breaking up the functionality of your application into logical controllers.

Adam


#3

Should the controller for this challenge be a subclass of NSObject, NSWindowController or NSViewController? What are the deciding factors? :question: