Discussion in 'Mac Programming' started by liptonlover, Jun 1, 2008.

  1. liptonlover macrumors 6502a

    Mar 13, 2008
    I'm working through Hillegass' book, and it's bringing up delegates. The problem is, it never defines what a delegate is and because of it I can't complete one of the exercises. Can anyone please help?
  2. Krevnik macrumors 68040


    Sep 8, 2003
    Delegates are objects that implement all or part of an 'informal protocol', and attach themselves as the delegate object for something else (see the -delegate and -setDelegate: methods).

    Each object that can have a delegate will use it differently, and have a different informal protocol. NSTableView and NSApplication can both have delegates for example, but each one expects its delegate to implement different methods.

    If you want to know what delegate methods a particular class supports, you will need to look at the class reference documentation for that class.
  3. aLoC macrumors 6502a

    Nov 10, 2006
    It's a way of customizing one of Apple's classes. Basically you make your own object and tell Apple's object about it. Then Apple's object calls yours at certain times, thus *in effect* you have added your code to Apple's object.

    In normal OO you would subclass a class to add your code to it. This is just a different way of doing it (a "design pattern") that gives the same effect without the need to subclass.
  4. cmaier macrumors G5

    Jul 25, 2007
    I think he defines what a delegate is, but does so by calling it a "helper class." Then he switches to referring to it as a delegate later on.
  5. Krevnik macrumors 68040


    Sep 8, 2003
    Delegates have one advantage, you can have one delegate object for multiple other objects. In some cases, it is useful.
  6. liptonlover thread starter macrumors 6502a

    Mar 13, 2008
    yes he does have a section about helper objects... that makes sense. Thanks everyone!

Share This Page