I’m trying to wrap my head around singletons and I understand that the App Delegate is essentially a singleton object. I’m trying have some member variables in App Delegate that I can access from any other class. I did this in the App Delegate:
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *viewController;
int screenwidth;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic) int screenwidth;
Then in the .m I did this:
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
...
screenwidth=400; //arbitrary test number
Now I have another class in the project, and it does this in the .h:
#import "AppDelegate.h"
In the .m I have this somewhere:
test=(AppDelegate*)[[[UIApplication sharedApplication] delegate] screenwidth];
However, it claims that “screenwidth” is an instance method that is not found. I also tried this:
test=(AppDelegate*)[[UIApplication sharedApplication] delegate].screenwidth;
This uses the dot syntax since screenwidth was synthesized, but it claims that property screenwidth not found
I’m sure these are basic issues that can be corrected simply. Any help appreciated.
Consider trying:
I think your two tries are trying to cast the
.screenwidthresult to anAppDelegate*.