本文介绍了将NSArray保存到NSUserDefaults并将其保存在NSMutableArray中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 c $>
How can I save NSArray in NSUserDefaults and then load it back in an NSMutableArray to populate the UIPickerView?
此外,问题是添加新的值到 NSMutableArray ,然后该数组将转换为 NSArray ,保存在 NSUserDefaults ( NSMutableArray 无法保存在 NSUserDefaults )中。
Also the issue is that new values would be added to that NSMutableArray and then that array will be converted to NSArray to be saved in NSUserDefaults (as NSMutableArray can't be saved in NSUserDefaults).
任何帮助。
感谢
推荐答案
[[NSUserDefaults standardUserDefaults] setObject:yourMutableArray forKey:@"Key"];
一个可变数组可以存储,因为它是NSArray的子类。
A mutable array can be stored since it is a subclass of NSArray.
要获取NSMutableArray的值:
To get the value as an NSMutableArray:
NSMutableArray *array = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"Key"]];
或
NSMutableArray *array = [[[NSUserDefaults standardUserDefaults] objectForKey:@"Key"] mutableCopy];
这篇关于将NSArray保存到NSUserDefaults并将其保存在NSMutableArray中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!