Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrCrispy

macrumors member
Original poster
Apr 10, 2008
71
0
Jacksonville, Florida
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?
 
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?

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.
 
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).
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, ...

What I'm ultimately looking for is kind of an App delegate feature summary or something. AppDelegates for dummies, perhaps?
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.