本文介绍了核心数据 - 获取唯一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用Core Data的iPhone应用程式。我只有一个实体叫做Books,该实体具有Title,Author,ISBN,Description和Shelf的属性。

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.

我正在编辑图书视图,想要有一个UIPickerView列出所有独特的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.

我的问题是 - 如何获得一个NSArray的所有的数据库中所有书的独特Shelf属性?我可以访问正在编辑的Book的managedObjectContext,所以我会使用某种获取请求吗?

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?

谢谢!

推荐答案

您可以使用 @distinctUnionOfArrays

但IMO将是一个更清洁的解决方案来重新设计您的数据模型,以便有两个实体(书和货架)。

然后您可以创建书和货架之间的关系。

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.

这篇关于核心数据 - 获取唯一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 12:10