avoid duplicate results on Core Data fetch

∥☆過路亽.° 提交于 2019-12-03 20:56:13

From the documentation of returnsDistinctResults:

This value is only used if a value has been set for propertiesToFetch.

From the documentation of propertiesToFetch:

This value is only used if resultType is set to NSDictionaryResultType.

From the documentation of resultType:

The default value is NSManagedObjectResultType.


This all tells me that the propertiesToFetch is ignored because you haven't set the resultType yourself and the default it to return managed objects instead of dictionaries. Since the propertiesToFetch is ignored the returnsDistinctResults is ignored as well and thus you are still getting duplicates.

Try setting the result type to return dictionaries instead of managed objects.

request.resultType = NSDictionaryResultType;

In addition to David Rönnqvist answer I suggest a useful link (with a sample) on selecting distinct values with Core Data:

core-data-how-to-do-a-select-distinct

Hope that helps.

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