Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-10-2009, 02:20 AM   #1 (permalink)
Candy Mountain, Charlie..
 
ovidiu's Avatar
 
Join Date: Mar 2009
Location: Romania
Age: 23
Posts: 116
Default 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?
__________________
Junior iPhone Developer
Mobile Touch Romania

Last edited by ovidiu; 07-10-2009 at 03:44 AM.
ovidiu is offline   Reply With Quote
Old 07-10-2009, 03:29 AM   #2 (permalink)
ftm
FasterThanMonkeys.com
iPhone Dev SDK Supporter
 
Join Date: Mar 2009
Location: Southern California
Posts: 521
Send a message via AIM to ftm
Default

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.
__________________


Website: http://fasterthanmonkeys.com

iScore Baseball Scorekeeper Top baseball scorekeeping app for iPhone
Bug Squash Reached #1 kids game in 15+ countries including USA, now with OpenFeint
Jam Packed! Fun puzzle game for all ages
Jam Packed Christmas Holiday puzzle game!
iScore Basketball Scorekeeper Best basketball scorekeeping application
ftm is offline   Reply With Quote
Old 07-10-2009, 03:43 AM   #3 (permalink)
Candy Mountain, Charlie..
 
ovidiu's Avatar
 
Join Date: Mar 2009
Location: Romania
Age: 23
Posts: 116
Default

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.
__________________
Junior iPhone Developer
Mobile Touch Romania
ovidiu is offline   Reply With Quote
Old 07-10-2009, 03:45 AM   #4 (permalink)
ftm
FasterThanMonkeys.com
iPhone Dev SDK Supporter
 
Join Date: Mar 2009
Location: Southern California
Posts: 521
Send a message via AIM to ftm
Default

Quote:
Originally Posted by ovidiu View Post
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.
__________________


Website: http://fasterthanmonkeys.com

iScore Baseball Scorekeeper Top baseball scorekeeping app for iPhone
Bug Squash Reached #1 kids game in 15+ countries including USA, now with OpenFeint
Jam Packed! Fun puzzle game for all ages
Jam Packed Christmas Holiday puzzle game!
iScore Basketball Scorekeeper Best basketball scorekeeping application
ftm is offline   Reply With Quote
Old 07-10-2009, 04:00 AM   #5 (permalink)
Candy Mountain, Charlie..
 
ovidiu's Avatar
 
Join Date: Mar 2009
Location: Romania
Age: 23
Posts: 116
Default

Quote:
Originally Posted by ftm View Post
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.
__________________
Junior iPhone Developer
Mobile Touch Romania
ovidiu is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,320
Threads: 39,117
Posts: 171,513
Top Poster: smasher (2,576)
Welcome to our newest member, xX Holllish Xx
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0