Help for NSPredicate, please…

Hello,

What’s wrong in this syntax?

NSPredicate *predicate = [NSPredicate predicateWithFormat: @“(NOT self IN self.avoidances) AND (NOT SELF == $SELF)”];

The goal is to get an array of objects which are different from the caller and not included in a set of caller’s entities. For example, a menu giving choices for a relationship with an object A has to list every object EXCEPT the object A itself and objects that are already in relation with A.

I get “Unable to parse the format string” error and I can’t understand how to formulate this.

Thanks,

Hi,

try a block predicate


  NSPredicate *predicate = [NSPredicate predicateWithBlock: ^BOOL(id obj, NSDictionary *bind){
		return ![self.avoidances containsObject:obj] && obj != self;
	}];

Thank You Stefan. I had to modify your code slightly to insert it in the Document method, because “self” refers to the document:

The Predicate with format could use “SELF” because it is a fetch property of the entity “Student”. By the way, fetch properties declared this way seem to wait for the PersistantStoreCoordinator to save the context before returning a correct array.

Well, the same question on StackOverflow is still waiting for an answer for more than a week now…

Thank you ! Sometimes I wonder if you are dreaming in Objective-C… :slight_smile:

Definitely no