07-10-2009, 03:20 AM
#1 (permalink )
Candy Mountain, Charlie..
Join Date: Mar 2009
Location: Romania
Age: 25
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 04:44 AM .
07-10-2009, 04:29 AM
#2 (permalink )
FasterThanMonkeys.com
Join Date: Mar 2009
Location: Southern California
Posts: 523
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, 04:43 AM
#3 (permalink )
Candy Mountain, Charlie..
Join Date: Mar 2009
Location: Romania
Age: 25
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, 04:45 AM
#4 (permalink )
FasterThanMonkeys.com
Join Date: Mar 2009
Location: Southern California
Posts: 523
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, 05:00 AM
#5 (permalink )
Candy Mountain, Charlie..
Join Date: Mar 2009
Location: Romania
Age: 25
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: 907
27 members and 880 guests
alapimba , armmzz , at0m87 , aziz , Azuresilver , brush51 , cacao , Desert Diva , Erwin , eviolet4 , fiftysixty , ghz.rai , headkaze , mavericki , mikeirvingapps , pratikchandak , ramonpadillas , rcheguraju , Remzuidferdenz , richardpaul , Shimi256 , sneaky , Thomas , ziocleto , Zuningo
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,311
Threads: 89,035
Posts: 379,819
Top Poster: BrianSlick (7,086)
Welcome to our newest member, ramonpadillas