开发者

NSApplicationDelegate class design

I have created my first complex OS X application. While working on it, I've had some doubts about how I use the class that implements the NSApplicationDelegate protocol (the class Xcode creates by default for Cocoa applications, i.e. MyApplicationAppDelegate.m/h).

In many tutorials (and books), I see that people create an AppController class to manage main or generic application tasks. I prefer to add my开发者_运维技巧 generic tasks directly into MyApplicationAppDelegate and create specific controllers depending on the modules I need to manage.

For example, I add into MyApplicationAppDelegate every IBAction used to open other windows (i.e. opening a preference panel), every function that isn't strictly connected with a specific module/controller and IBOutlets for the main interface. In MyApplicationAppDelegate I also add every reference to controllers used in my application. That's essentially about it.

I'm really confused because I'm not sure whether or note this is good design. Has MyApplicationAppDelegate been designed for some other purpose?

I would like any suggestions and if possible any articles you might know of about design patterns for Cocoa.


Xcode used not to create an application delegate class in the Cocoa Application template by default.

I believe Apple only introduced the automatic creation of an <AppName>_AppDelegate class with their project template fairly recently, maybe in version 3.2 or so.

This is why many older books and tutorials have you create an AppController class, because the old project template did not create one for you.

You are free to use the <AppName>_AppDelegate as your main controller class, and the reason Apple adds it to their template is that so many developers use the NSApplicationDelegate object as their main application controller.

An excellent resource to learn more about design patterns in Cocoa is the book appropriately called Cocoa Design Patterns.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜