Setting up a custom class with a delegate

Discussion in 'Mac Programming' started by RossOliver, Jun 25, 2008.

  1. macrumors regular

    Joined:
    Nov 6, 2006
    #1
    Hey,

    What I need is for a class of my own, say MyClass, to be able to send messages to a class that uses it, say MyOtherClass. For instance, if MyClass is running a variable length timer and when the timer expires it needs to notify MyOtherClass to handle it, how would I go about setting up the required relationship?

    I'm sure there is an article somewhere on what I need and I would be grateful if someone could point me to one if they know of any, or try and give me a breif explanation of the steps I need to take...

    Cheers,

    -Ross
     
  2. macrumors 6502

    Joined:
    Apr 28, 2008
    #2
    I'm assuming you've got some programming experience based on this question. Languages like Java and C# require you to attach listeners to objects that have events, a form of loose coupling.

    This article on Apple's developer site should be pretty useful to you.
     
  3. thread starter macrumors regular

    Joined:
    Nov 6, 2006
    #3
    Just what I was after, cheers :)

    I have another question which I may as well ask in here instead of starting a new thread...

    In my AppDelegate class I open a connection to an sqlite database, with a reference to the database stored as an instance variable (accessible via a get method).

    I need to get at this reference in my main view controller. My main view is loaded automatically, though (with [window makeKeyAndVisible] and the nib specified in a plist). How do I go about calling a custom init method in my main view controller which will allow me to pass the database reference in:

    initWithDatabase: ( sqlite3 * )database;

    Thanks for your time,

    -Ross
     

Share This Page