Different NSPredicate subclasses don't class as equal even if predicates are

Originator:apilky
Number:rdar://11226996 Date Originated:11-Apr-2012 03:12 PM
Status:Open Resolved:No
Product:Mac OS X SDK Product Version:10.7
Classification:Other Bug Reproducible:Always
 
Summary:
The equality test for NSPredicate seems to take into account the class of the subclass. The class doesn't matter at all when comparing predicates. If you want a specific class you can use isKind/MemberOfClass: for that. Otherwise equality should test the equality of the predicate itself, in which case it is equal.

Steps to Reproduce:
Try the following code:

NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"complete = 0"];
NSPredicate *predicate2 = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObject:predicate1]];
NSLog(@"%d", [predicate1 isEqual:predicate2]);

Expected Results:
Prints out 1

Actual Results:
Prints out 0

Notes:
I understand they aren't strictly 100% equal, but neither is a mutable array and its immutable copy. The fact is predicate1 and predicate2 are semantically equal. They both represent the same test and given the same objects they will always return the same result. If I built a compound predicate like so it returns a 1 like you expect:

NSArray *subpredicates = [NSArray arrayWithObjects:[NSPredicate predicateWithFormat:@"foo = 0"], [NSPredicate predicateWithFormat:@"bar = 1"], nil];
NSPredicate *predicate1 = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"foo = 0 AND bar = 1"];
NSLog(@"%d", [predicate1 isEqual:predicate2]);

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!