Reputation: 761
I have a big amount of data (more then 100 entries) to show on a table view. The data will be static, so i was thinking in store it on a plist file. 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?
Upvotes: 0
Views: 142
Reputation: 1033
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]];
}
Upvotes: 1
Reputation: 19098
There is no "best way", but one viable approach is to use a JSON file. If the data isn't too large, say the JSON file is much less than 1 MByte.
Creating and modifying a JSON file is quite comfortable in an editor. You can parse and create a representation as usual with 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.
Upvotes: 2
Reputation: 5393
100 entres isn't actually a large amount of data.
I would be inclined to use a plist for this small amount of data.
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).
Or, you could use a separate plist for the user-data.
Upvotes: 2