开发者

NSDictionary as a data structure for objects question

开发者 https://www.devze.com 2023-03-21 10:45 出处:网络
I just wanted to make sure I don\'t need Core Data for a simple example.If I have a UITableView where the user can hit the plus sign to add new table entri开发者_JAVA技巧es, and each entry corresponds

I just wanted to make sure I don't need Core Data for a simple example. If I have a UITableView where the user can hit the plus sign to add new table entri开发者_JAVA技巧es, and each entry corresponds to an individual timer event, do I store each object added to the table in an NSDictionary? Thanks.


NSMutableArray would be a better choice. An array is an ordered list, just as a table is. A dictionary is not ordered, so it's not a good match for a table.

If that's confusing, try thinking about it in concrete terms. Imagine that you have a table and you've stored the data for the table in a dictionary. At some point, the table will ask it's data source -- probably your view controller -- to provide a cell for a particular row of the table. How do you figure out which entry of the dictionary corresponds to that cell? On the other hand, if you use an array, the mapping between table rows and data items is simple.

0

精彩评论

暂无评论...
验证码 换一张
取 消