如何将NSArray存储到plist或数据库中? [英] How to store a NSArray into plist or database?
问题描述
我有这个应用程序,当我按下某个按钮时,该应用程序必须存储信息.事实是,当我按下此按钮时,我需要将该数据存储在本地,以便可以在其他视图中加载该数据,并将其加载到将其显示为数据.
I have this app which has to store information when I hit some button.. The fact is, when I hit this button I need to store this data locally so I can take this in other view which is going to load it at show it as data.
我在考虑某些折弯或数据库.问题是我无法想到一个主意或好东西.
I'm thinking in some plis or database. The problem is I can't get to an idea or something good.
- 我将对象传递给数组.
- 我有按钮.
哪种方法是将整个阵列存储在手机中的最佳方法,因此我可以像存储它一样读取它吗?
Which is the best way to store the entire array inside the phone, so I can read it as the same way it is stored?
如果不清楚,请告诉我.
If this is not clear, please tell me.
预先感谢
推荐答案
简便方法是将其保存到plist
Easies way is to save it to a plist
赞:
//create array
NSMutableArray *arr = [[NSMutableArray alloc] init];
//Add data
[arr addObject:@"some object"];
//String Path of file
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
//Save
[arr writeToFile:path atomically:YES];
以后像这样加载它:
//Load it
NSMutableArray *arr = [[NSMutableArray alloc] initWithContentsOfFile:path];
这篇关于如何将NSArray存储到plist或数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!