In a Core Data object, how to use the attribute of the source object in its property predicate?

I use a visual editor to create a basic data model. I cannot figure out how to set the predicate of a given property so that it uses the attributes of the original object in the predicate.

For example, I have EntityAwith an attribute searchId. I also have EntityBwith attribute id. I want to find all instances EntityBwhose atrribute idis equal EntityA searchId. When I try to edit the predicate, the drop-down list for the left and right sides contains only the keys for the destination, which in this case is equal EntityB, and there is no way to select any key from EntityA.

I know that you can just create a predicate programmatically, but I was wondering if there is a way to do this using a visual editor.

+3
source share
1 answer

This is a bit of a pain.

First, in the predicate editor editor, click in the empty field to the right of the last predicate field and select " variable". Then enter " FETCH_SOURCE.attributeName" in the box.

FETCH_SOURCE (or $ FETCH_SOURCE in code) is a special variable that indicates the object sending the selection for the selected property. There is also FETCHED_PROPERTY ($ FETCHED_PROPERTY) that returns an NSFetchedPropertyDescription object.

So, your predicate in the text is as follows:

id==$FETCH_SOURCE.searchId

Apple, -, , . , .

+6

All Articles