简体   繁体   English

在应用中预存储大量数据

[英]Pre store big amount of data in app

I have a big amount of data (more then 100 entries) to show on a table view. 我有大量数据(超过100个条目)要显示在表视图上。 The data will be static, so i was thinking in store it on a plist file. 数据将是静态的,因此我正在考虑将其存储在plist文件中。 The problem is when it is shown in table view, the user will be able to select or deselect a row and this information must be stored. 问题是当它以表格视图显示时,用户将能够选择或取消选择一行,并且必须存储此信息。

In other words the app will have a list of things and the user can select the things he own. 换句话说,该应用程序将具有事物列表,用户可以选择自己拥有的事物。

What's the best way to store the data in the app and the selected information? 在应用程序中存储数据和所选信息的最佳方法是什么?

PS.: I was avoiding Core Data, but if this is the best way how can i pre store the data in an entity? PS .:我避免使用Core Data,但是如果这是最好的方法,那么如何将数据预先存储在实体中?

100 entres isn't actually a large amount of data. 100 ent实际上并不是大量数据。

I would be inclined to use a plist for this small amount of data. 我倾向于对少量数据使用plist。

If you wanted, you could keep the user-data in the same plist too: When app first runs it could copy the plist to the document directory so that it can be edited (the ownership data written). 如果需要,您也可以将用户数据保留在同一plist中:在应用程序首次运行时,它可以将plist复制到文档目录中,以便可以对其进行编辑(写入所有权数据)。

Or, you could use a separate plist for the user-data. 或者,您可以为用户数据使用单独的plist。

There is no "best way", but one viable approach is to use a JSON file. 没有“最佳方法”,但是一种可行的方法是使用JSON文件。 If the data isn't too large, say the JSON file is much less than 1 MByte. 如果数据不是太大,则说明JSON文件远小于1 MB。

Creating and modifying a JSON file is quite comfortable in an editor. 在编辑器中创建和修改JSON文件非常方便。 You can parse and create a representation as usual with NSJSONSerialization . 您可以像往常一样使用NSJSONSerialization解析和创建表示NSJSONSerialization

Hint : A JSON file which has N number of bytes, creates a representation of Foundation objects which roughly need a total of 5*N to 10*N allocated space. 提示 :一个具有N个字节数的JSON文件,创建了一个Foundation对象的表示形式,这些对象大约总共需要5 * N到10 * N个分配的空间。

The easiest way to track the selected and unselected row is here: this code will save value with your tap on the cell. 跟踪选定和未选定行的最简单方法是在这里:此代码将在您点击单元格时保存价值。

   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    BOOL isSelected=[[NSUserDefaults standardUserDefaults] boolForKey:[indexPath.row stringValue]];
    [[NSUserDefaults standardUserDefaults] setBool:!isSelected forKey:[indexPath.row stringValue]];

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM