i am kind of new to saving NSMutableArray To NSUerdefaults.
here is the declaration of the iVar:
.h file
@interface GameData : NSObject {
NSMutableArray *PPLayers;
}
@property (nonatomic,retain) NSMutableArray *PPLayers;
.m file
@synthesize PPLayers;
here is how i am adding a object to the array and saving it to the default:
-(void)AddObject:(NSString *) object ToArray:(NSMutableArray*)array{
if (array == PShoes) {
[PShoes addObject:object];
NSLog(@"Object : %@",object);
[[NSUserDefaults standardUserDefaults]setValue:PPLayers forKey:@"pplayers"];
[[NSUserDefaults standardUserDefaults]synchronize];
NSLog(@"%@",PPLayers);
}
sometimes it works and sometime the app crashes.
and here is how i am trying to load the array:
PPLayers = [[NSUserDefaults standardUserDefaults]mutableArrayValueForKey:@"pplayers"];
something is wrong here but i dont know what.
sometimes when i load it it gives me null.
the app save it only when i run it from the simulator.
i would like to get some help plz.
thanks!
try this