 |
 |
|
 |
07-10-2009, 03: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 04:44 AM.
|
|
|
07-10-2009, 04:29 AM
|
#2 (permalink)
|
|
FasterThanMonkeys.com
iPhone Dev SDK Supporter
Join Date: Mar 2009
Location: Southern California
Posts: 517
|
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: 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, 04:45 AM
|
#4 (permalink)
|
|
FasterThanMonkeys.com
iPhone Dev SDK Supporter
Join Date: Mar 2009
Location: Southern California
Posts: 517
|
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: 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: 472 |
| 43 members and 429 guests |
| al31, alexgiul, atsd, axeman, black666, bravetarget, BrianSlick, ChrisJW, ChrisMayer, DevSdk, d_CFO, finefin, ggalante, GhostDog, invisigoth, iPhoneDevelopment, itakenocrud, johnnybluejeans, josep@sixtemia.com, lbergelt, LemonMeringue, Maximilian, MiniRobinho, mlo, msu, ncmacman, nibby, Noise, sebswift, spark86, svguerin3, their, themathminister, tturk, umarmara, vcanic, warmi, winklllll, wooyaiz, x2on, ztaksoftware, ZunePod |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,504
Threads: 35,782
Posts: 156,774
Top Poster: smasher (2,449)
|
| Welcome to our newest member, itakenocrud |
|