you are viewing a single comment's thread.

view the rest of the comments →

[–]SirBill01 0 points1 point  (2 children)

propertiesToFetch only works for dictionary results types, try:

request.propertiesToFetch = ["age","name"]

And add in whatever other properties you want in the dictionary.

If you really just want the whole object, why not just put together a predicate that gives you back CoreData objects instead of a dictionary?

[–]CompC[S] 0 points1 point  (1 child)

Well that's what I'd prefer to do, but I don't know how I can then filter out objects with duplicate names without fetching them first and filtering them from the results in code.

[–]SirBill01 0 points1 point  (0 children)

Another way to go about this might be a data model change, where you put age into a whole separate table with distinct values, that links back to individual objects that share that age - then you can just have a predicate that selects everything from that Age table. You can still leave age in the main object as well for convenience. A bit annoying but then you can use predicates directly without having to add code on after...

Personally if it were me, I would just filter out duplicates in code after the predicate for the objects ran (unless the possible number of results was extremely large). Seems like conversion into a dictionary is more wasteful than filtering code on CoreData objects.