 |
 |
|
 |
07-10-2009, 02:20 AM
|
#1 (permalink)
|
|
Candy Mountain, Charlie..
Join Date: Mar 2009
Location: Romania
Age: 23
Posts: 116
|
appDelegate synthesizing
Hello everyone.
I was just wondering how you people deal with the appDelegate.
So for me, the way I do it is the next one:
Code:
@interface MyClass : NSObject {
MyAppDelegateClass *appDelegate;
}
@property (nonatomic, assign) MyAppDelegateClass *appDelegate;
@implementation MyClass
@synthesize appDelegate;
-(id) init{
[self setAppDelegate:(MyAppDelegateClass *)[[UIApplication sharedApplication] delegate]];
return self;
}
@end
Nothing is wrong so far, but I just wanted to know if that is a good habit to use or not. How do you do it?
Last edited by ovidiu; 07-10-2009 at 03:44 AM.
|
|
|
07-10-2009, 03:29 AM
|
#2 (permalink)
|
|
FasterThanMonkeys.com
iPhone Dev SDK Supporter
Join Date: Mar 2009
Location: Southern California
Posts: 521
|
You don't need to store another reference to the App Delegate. Any time you need it, just call:
Code:
MyAppDelegate* delegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
And replace MyAppDelegate with whatever the class name for your App Delegate is.
|
|
|
07-10-2009, 03:43 AM
|
#3 (permalink)
|
|
Candy Mountain, Charlie..
Join Date: Mar 2009
Location: Romania
Age: 23
Posts: 116
|
Yes, but I want to use the appdelegate in a lot of methods inside the applications, I don't like to write that whole line. I just wanted to use a shorter version, which is appDelegate.
|
|
|
07-10-2009, 03:45 AM
|
#4 (permalink)
|
|
FasterThanMonkeys.com
iPhone Dev SDK Supporter
Join Date: Mar 2009
Location: Southern California
Posts: 521
|
Quote:
Originally Posted by ovidiu
Yes, but I want to use the appdelegate in a lot of methods inside the applications, I don't like to write that whole line. I just wanted to use a shorter version, which is appDelegate.
|
How about just creating a #define like this:
Code:
#define APPDELEGATE ((MyAppDelegate*)[[UIApplication sharedApplication] delegate])
Now anywhere you want to access the App Delegate, just use "APPDELEGATE" in code.
|
|
|
07-10-2009, 04:00 AM
|
#5 (permalink)
|
|
Candy Mountain, Charlie..
Join Date: Mar 2009
Location: Romania
Age: 23
Posts: 116
|
Quote:
Originally Posted by ftm
How about just creating a #define like this:
Code:
#define APPDELEGATE ((MyAppDelegate*)[[UIApplication sharedApplication] delegate])
Now anywhere you want to access the App Delegate, just use "APPDELEGATE" in code.
|
Very nice elegant solution, I didn't think of that. Thanks.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 346 |
| 41 members and 305 guests |
| AgCode, alekssebasstrs, Batman, Bertrand21, bglodde, BrianSlick, CapsicumDreams, Chilibird, chrish2os, computermatt, davidneal, desireapps, EmprendeSoft, Eric 54, flamingliquid, graph, harkonian, Hololont, iTrackiGiveaway, itzdark, jamison, JasonR, javaconvert, joalta, justill45, kanso, Kyowoo, miniyou64, mobiledna, Moddy, moehac, Parental, rendezvouscp, Rudy, scotopia, SimonCowell, sjarman, snowboarderz69, stlau, superstec, walkman2001 |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,320
Threads: 39,117
Posts: 171,513
Top Poster: smasher (2,576)
|
| Welcome to our newest member, xX Holllish Xx |
|