How to display an NSSet in a UITableView?

♀尐吖头ヾ 提交于 2019-12-14 00:45:05

问题


How would you proceed to display the content of an NSSet in a UITableView?

As you know, the table view will ask for the element at a given row, but since the NSSet elements aren't ordered, this doesn't mix well.

My current solution is to iterate through the NSSet until I reach the element at a given index, but this really doesn't feel right.

You may ask why I don't use an NSArray instead. This is because I'm using Core Data, which uses NSSets to store collection of elements.

Any help would be appreciated.


回答1:


Since you're only displaying the elements, why not take the NSSet, and call -[allObjects] on it to get a NSArray?

If your data changes, you'll have to re-fetch anyway, even with a NSSet, and apart from the initial conversion from the NSSet, using the array is quite fast.



来源:https://stackoverflow.com/questions/1439357/how-to-display-an-nsset-in-a-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!