Pete Pete - 7 months ago 18
Swift Question

Fetch individual attributes only once each

I am new to Core Data and am attempting something which seems to be simple but is elusive to me.

Entity: Person

Attribute: First Name

I would like to fetch all First Name attributes but only have each one show once. That means that if "Peter" exists 5 times it would only be fetched once.
I could fetch all "First Name" attributes and then iterate through it and compare all first names but this seems so clumsy. Is there a faster, more elegant way?

Answer

Coredata provide a property to get distinct Results. Use as below:

request.returnsDistinctResults = true
Comments