AppDelegate?

Discussion in 'Mac Programming' started by dg1234uk, Dec 22, 2009.

  1. dg1234uk macrumors newbie

    Joined:
    Jun 1, 2009
    #1
    I have come back to learning cocoa after a break (having learnt the basics of OOP with Java) and I am using the Aaron Hillegass's book 'Cocoa Programming for Mac OS X'.

    I have noticed since coming back and updating to snow leopard + xcode 3.2.1 when i create a project and get a class [projectName]AppDelegate and a instance of this class is created in the MainMenu.xib. Is this to replace creating an AppController class (as done in above mentioned book)? Is there any reference docs that can explain AppDelegate?

    Thanks
     
  2. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    Well if its appending AppDelegate to a file name then I sure hope that means it is putting something like <UIApplicationDelegate> in the class definition in the .h file.

    In this case you can just hold option and double click the UIApplicationDelegate word to pop up a reference and hit the book icon on the top right hand side to open Apple's documentation.

    This is how it is in all my iPhone projects. Basically the app delegate is who gets sent messages like applicationWillTerminate and the like by default. You can have any class or instance you create register with the notification center to receive similar notices for saving files and cleanup.
     
  3. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #3
    Go to bignerdranch.com and look at the description of the book. There is a comment on just that behavior.
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    It's just the new project template format. To be honest, it's quite annoying, especially if you're creating a backwards compatible project.

    You can delete the classes from Xcode and in IB and recreate your own.
     
  5. dg1234uk thread starter macrumors newbie

    Joined:
    Jun 1, 2009
    #5
    Thanks all for replies!

    Is there any advantage to using it or should I just to stick to what I am doing and delete it.
     
  6. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #6
    Umm the advantage to using it is to conveniently call certain methods on that class when various things happen to your application like when it launches or is about to close.

    You could of course delete that and add the delegate functionality somewhere else or, again, register with NSNotificationCenter to receive similar notifications.

    ... or you could just leave it and down the road if you need to use any of those features you kinda already have it setup already.
     
  7. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #7
    If you're still learning, I'd remove it for now. The protocol is not really needed if you set the app delegate inside the nib, which the template already does for you.
     

Share This Page