So, I'm trying to fix this annoying mistake. If I filter my array as an ideal version with NSPredicate, I will get EXC_BAD_ACCESS because it is trying to trigger a release on the object passed as a delegate, extra time. If I filter with the working version, it works fine. I thought these two implementations were identical. Where am I going wrong? I know that the predicate method is the way, it just cannot make it work correctly.
- (NSArray *)foosWithDelegate:(id)delegate {
return [foos filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"delegate = %@", delegate]];
}
- (NSArray *)foosWithDelegate:(id)delegate {
NSMutableArray *results = [[NSMutableArray alloc] init];
for (MYFoo *foo in foos) {
if (foo.delegate == delegate) {
[results addObject:foo];
}
}
if ([results count] == 0) {
[results release];
return nil;
}
return [results autorelease];
}
foosis ivar. The class MYFoohas a property for the delegate, which assign. The problem still occurs, even if foosempty.
source
share