Take the 2-minute tour ×

I created a class AppSettings containing booleans:

#import <Foundation/Foundation.h>

@interface AppSettings : NSObject{

bool bip10secCountdown;
bool jv10secCountdown;
bool jv30secAlert;
bool jv1minAlert;
bool jvp5minAlert;


@property bool bip10secCountdown;
@property bool jv10secCountdown;
@property bool jv30secAlert;
@property bool jv1minAlert;
@property bool jv5minAlert;


And the implementation:

#import "AppSettings.h"

@implementation AppSettings

@synthesize bip10secCountdown, jv10secCountdown, jv30secAlert, jv1minAlert, jv5minAlert;

- (id)init
    self = [super init];
    if (self){
    return self;



Then I'm trying to use this class in my main class but after initializing the object in the viewDidLoad, when I want to use it again it appears as null.. So I guess it's released too early. I'm using ARC so I don't manually manage the memory. Am I doing something wrong ?

The declaration in the main class:

AppSettings *appSettings;


@property(nonatomic)bool activated;
@property (nonatomic, strong) AppSettings *appSettings;

And the implementation:

@synthetize appSettings
- (void)viewDidLoad
    // Initialize the model
    self.appSettings = [[AppSettings alloc]init];

NSLog(@"appSettings = %@",self.appSettings);

The first output is OK. But then when I try to access appSettings from another method in the Main class, the appSettings is (null)

Thank you for your help.

share|improve this question
What is the other method (in the Main class) you are referring to? This error is ussualy caused by trying to access details initializd in viewDidLoad before the view is loaded. –  Mihai Timar Apr 13 '12 at 9:52
add comment

3 Answers

The view has most likely unloaded, or your view controller has been released. Try moving the initialization code to the method where your view controller is initiated(- (id)initWithNibName: bundle:)

share|improve this answer
Hi, thank you for answering, I tried to do that (my view controller is initiated in the AppDeletage) but the behavior is still the same.. –  Sinan Apr 5 '12 at 1:56
add comment

Instead of:

@property (nonatomic, strong) AppSettings *appSettings;


@property (nonatomic, retain) AppSettings *appSettings;

And I'd recommend to make your AppSettings as a Singleton-class.

share|improve this answer
Hi, thank you for answering. I tried it but it doesn't solve the problem. –  Sinan Apr 5 '12 at 1:57
Then try to move your viewDidLoad content to init or loadView. PS. Again. Make AppSetting as a Singleton. It'll be work :) –  demon9733 Apr 5 '12 at 6:20
add comment

When you say you initialise the view contoller in AppDelegate I presume you mean MyViewController *theView = [[MyViewController alloc] init]; or something like that. That will be your first view and you should initialise AppSettings in viewDidLoad of MyViewController, not the AppDelegate.

demon9733 suggestion regarding making AppSettings a singleton is a good one as you will be able to easily access your settings from anywhere in the app.

Also verify whether ARC is being used for MyViewController (or whatever it might be)

share|improve this answer
add comment

Your Answer


