Pregunta

How can I fetch related objects through one attribute and dump it in nsarray in one line?

Like this entity1attribute.enRelated.entity2attribute.

This is one-to-one relationship.

¿Fue útil?

Solución

Don't dump them into an array. Use a NSFetchedResultsController. You will then be able to write many one-liners.

Anyway, the code logic is the same. Supposed you have all objects fetched in fetchedObjects, you can do this:

NSArray *filtered = [fetchedObjects filteredArrayUsingPredicate:
 [NSPredicate predicateWithFormat:@"otherEntity.attribute = %@", value]];

You could shorten this with a category on your managed object subclass and make it as simple as:

[myObject otherEntitiesWithAttribute:value];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top