Hi there,
I'm pretty new in IPhone Development, so maybe you can help me with this problem:
I'm having an object "preferences" that holds a single NSString: (All code simplified...)
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface Preferences : NSObject {
NSString *username;
}
-(void)loadPreferences;
@property(nonatomic,retain) NSString *username;
@end
The implementation looks like this:
#import "Preferences.h"
@implementation Preferenes
@synthesize username;
-(void)loadPreferences{
username=@"MyUser";
}
-(void) dealloc {
[username release];
}
@end
Next, I'm using a retain reference to this object in my main delegate:
#import <UIKit/UIKit.h>
@interface MainDelegate : NSObject <UIApplicationDelegate> {
...
Preferences *prefs;
}
@property(retain,nonatomic) Preferences *prefs;
Implementation:
#import "MainDelegate.h"
#import "Preferences.h";
@implementation MainDelegate
@synthesize prefs;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
prefs=[[Preferences alloc] init];
NSLog(@"Username: %@",prefs.username); // THIS WORKS
}
So I can access prefs.username in the Main Delegate.
Now I want to access the preferences reference from my MainDelegate.
I'm trying to do this this way:
MainDelegate *delegate = (MainDelegate*) [[UIApplication sharedApplication] delegate];
Preferences *prefs=delegate.prefs;
// This works...
NSLog(@"The Username is: %@",prefs.username);
// CRASH
When I'm trying to access the "username" object within the preferences object, the programm crashes with only showing the GNU Licence Information.
I think there is something going wrong that maybe an object is already released when I try to access it...
Can you help me out ?
Thanks !