Core Data - Getting Unique Rows

為{幸葍}努か 提交于 2019-12-08 07:52:45

问题


I'm working on an iPhone app that uses Core Data. I have only one entity called Books, and that entity has the attributes Title, Author, ISBN, Description and Shelf.

I'm working on the book editing view, and want to have a UIPickerView listing all of the unique Shelf rows so that the user can just pick a shelf.

My question is -- how do I get an NSArray of all of the unique Shelf attributes across all of the books in the database? I have access to the managedObjectContext of the Book being edited, so would I use some sort of a fetch request?

Thanks!


回答1:


You can get a duplicate-less array of available shelves with the array operator @distinctUnionOfArrays.
But IMO it would be a cleaner solution to redesign your data model, so that there are two entities (books and shelves).
You could then create a relationship between book and shelf.



来源:https://stackoverflow.com/questions/1996279/core-data-getting-unique-rows

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