iphone - How to save integer value to NSuserDefault like sqlite? -


i want save , retrieve value in nsuserdefault. saving , retrieving value sucessfully. when go cak homepage , again come in class value not stored , process done again. doesnot remember old value.

i doing this-

-(void)viewdidload{     = 0;                // int a; defone in .h     [self calling_once]; }  -(void)calling_once{      nslog(@"a is: %d",a);     // 0 when leave class , return class. problem. want a=1; when go , return class       nsinteger b = [[nsuserdefaults standarduserdefaults] integerforkey:@"save_interger_value_for_formula_one"];  //is not able remeber value. gives a=0; b =0; when come class, want should return a=1; b=1; , remember old value sqlite when return class.       if (a==0) {          [self refreshbutton];          nslog(@"before increment is: %d",a);          a++;           nslog(@"after increment is: %d",a);           [[nsuserdefaults standarduserdefaults] setinteger:a forkey:@"save_interger_value_for_formula_one"];     }      nsinteger b = [[nsuserdefaults standarduserdefaults] integerforkey:@"save_interger_value_for_formula_one"];     b = a;      nslog(@" b is: %d",b);     b = a;     nslog(@" is: %d",a); } 

any idea or suggestions highly welcome.

try implement this..sure it'll help...

@implementation classa  - (void)viewdidload     {         [super viewdidload];         // additional setup after loading view, typically nib.         [[nsuserdefaults standarduserdefaults]setinteger:100 forkey:@"save_interger_value_for_formula_one"];         [[nsuserdefaults standarduserdefaults] synchronize];     }  @end  @implementation classb  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.        int b = [[[nsuserdefaults standarduserdefaults]        integerforkey:@"save_interger_value_for_formula_one"] integervalue];       nslog(@"interger value %d",b); } 

Comments