I have 2 arrays. The first is an array of dictionaries from a JSON feed. The second is just an array of values I’m using to populate a UITableView.
For each row in the table I need to know whether the value I’m writing to the table cell exists in the first array in any of the dictionaries, so I can set the accessory type appropriately. Is there a simple way of doing this, or would I be better off creating another array of the id values from each dictionary first?
I hope that makes sense, can’t see any other way to explain it 😉
You can use
indexesOfObjectsPassingTest:with a block that searches inside the dictionary, but it is suboptimal: you will be re-doing the same search over and over for each cell, which might slow down your app, especially when the user scrolls through your table quickly. You would be a lot better off creating anNSSetwith the items as soon as you get the feed, and re-use that when you render your table cells.Example:
Construct
NSSet *allIdswhen you receive your JSON feed, like this:When you need to decided whether or not to show your accessory view, do this: