views:

345

answers:

3

i am currently starting to learn Xcode and objective-c and i am reading three different books on that topic currently. All of these books refer to a file called "AppDelegate" (My_First_ProjectAppDelegate.m, My_First_ProjectAppDelegate.h) which are said to be "created with the Project" (i am creating a "Cocoa Application"). These files are not present when I create a new Project. I seem to be not the only one having this problem (see http://pragprog.com/titles/dscpq/errata ).

Is there any more information about AppDelegate? What is the current practice on how to deal with a missing Appdelegate? i am using Xcode Version 3.1.4 on Mac OSX Leopard.

+1  A: 

As I recall, only the iPhone templates were providing delegate classes by default. This is not a huge deal, but I can see how you would be concerned if you are just learning. Are you sure what you are reading is relevant to MacOS applications and not Iphone?

You can always create your own delegate class manually. You just create a class as you normally do, then set it as the delegate for NSApplication in Interface Builder.

darren
thanks for the fast answer! how would i "set it as the delegate for NSApplication in Interface Builder"?
z3cko
+6  A: 

AppDelegate is nothing more than a common NSObject class with needed connections in MainMenu.xib. You can easily recreate your own:

  1. Create a class, name it AppDelegate
  2. Open MainMenu.xib and add NSObject object to object palette
  3. In object inspector's Identity tab (the last one) set object's class to AppDelegate (you should get autocomplete)
  4. Ctrl+drag from Application object to your newly created AppDelegate object and choose "delegate" from opened panel.
Eimantas
thanks for the fast and easy-to-understand answer!
z3cko
+1  A: 

I think the confusion comes from the version of XCode you are using.

Xcode version 3.2 changed the default behavior when you create a new project: it now creates an AppDelegate for your project. I can't remember what the earlier versions did, but it was different.

As Eimantas says, if you want to use an AppDelegate then you can just create one following the steps he describes.

Benedict Lowndes