Questions on AppDelegates and life in general...

Discussion in 'iOS Programming' started by MrCrispy, May 4, 2010.

  1. MrCrispy macrumors member

    MrCrispy

    Joined:
    Apr 10, 2008
    Location:
    Jacksonville, Florida
    #1
    Ok, so I've read the documents at Apple and I've read tutorials and stacks of books. I still don't really GET appDelegates. Yes, I know that they pretty much handle the loading/unloading and view swapping and such (summarized I know but still).

    My main question is: what else, if anything, are they good for?

    Could I, say, declare an NSString in the app delegate and have it be set or accessed in various views in my app? If so how? (side note: if that's done in a way outside of appdelegate I'd like to know how but that's probably a different thread).

    What I'm ultimately looking for is kind of an App delegate feature summary or something. AppDelegates for dummies, perhaps?
     
  2. Legolover64 macrumors regular

    Joined:
    Feb 24, 2008
    #2
    AppDelegates can definitely be used to store/access data from tons of view controllers or classes, it's also the thing that you (correctly) stated loads and manages windows and app launching/crashing.

    If you'd like to, for example, access the app delegate from anywhere:

    Code:
    [UIApplication sharedApplication].delegate
    You can use this to access app delegate methods, data (assuming your @property's and @synthesize's are done correctly) and other state information.

    I hope this answers your question? They're weird, but there are some kinds of problems that are best solved using App Delegates.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    You could use the app delegate to store an NSString that is accessible throughout the app. Just make the NSString a property of your app delegate class. But you could do the same thing by storing the string in NSUserDefaults, or using a global variable, or by creating a singleton, or using CoreData, or via a property-list, ...

    There really is no feature summary. App delegates are something that are easily accessible throughout your application. So, it's really up to your imagination to come up with the possibilities. And just because you can use the app delegate for certain things, doesn't always mean it is the best (or recommended) way to do so.
     
  4. kaydell.leavitt macrumors regular

    Joined:
    Apr 19, 2010
    #4
    Delegates

    Delegates allow you to add functionality to an app without subclassing the app class.
     

Share This Page