0

When I create a predicate like this, from outside a subclass of NSManagedObject, it works just fine:

CNSTag *aTag = ...
_predicateForMatchingObjects = [NSPredicate predicateWithFormat:@"ANY tags == %@", aTag];

However, when I try to provide a function for my class CNSTag, as below, the program crashes while trying to create the predicate:

- (NSPredicate *)predicateForMatchingObjects {

_predicateForMatchingObjects = [NSPredicate predicateWithFormat:@"ANY tags == %@", self];
return _predicateForMatchingObjects;
}

If I access key paths of self in the predicate (e.g., "ANY tags.name == %@", self.name), it works fine; I just can't access self. Does anyone know why this is the case?

pickwick
  • 3,134
  • 22
  • 30
  • 1) Do you have any error message? Does it crash when the predicate is created, or when it is used? - 2) Where is `_predicateForMatchingObjects` declared? – Martin R Jan 27 '13 at 15:36
  • And are you using ARC or not (ARC turned off will indeed explain the crash, and the exception you got would tell you all about it) – AliSoftware Jan 27 '13 at 15:46
  • it's crashing when it's created, and i'm using ARC. I can't tell what exactly is causing the crash: it hangs up pretty badly and then puts me into the assembly language. It doesn't matter where the variable is declared: it can be declared right there or in the class implementation. It also doesn't matter how the predicate is created: i get the same problem if the predicate is created from NSExpressions. Creating an expression with self doesn't cause the crash; but creating the predicate from the expressions does. – pickwick Jan 27 '13 at 20:28
  • I still don't know what the problem is, but I fixed it. The function in which the predicate was created was defined in a getter for a transient attribute of the NSManagedObject subclass. I deleted that attribute from the model, and am now just treating it as conventional, unmodeled property of the NSManagedObject subclass. Everything now works as expected. – pickwick Jan 27 '13 at 20:46

0 Answers0