我需要保存一个NSMutableArray
到NSUserDefaults
.
我已经尝试过了,但是 load 方法返回一个nil
NSMutableArray
:
// NSMutableArray *listaAenviar = [[NSMutableArray alloc]init];
-(void) saveArray {
NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
[_listaAenviar addObject:@"1"];
[currentDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:[_listaAenviar mutableCopy]] forKey:@"listaAenviar"];
[currentDefaults synchronize];
}
-(void) loadArray {
NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
_listaAenviar = [currentDefaults objectForKey:@"listaAenviar"];
}