supermarin / ObjectiveSugar

ObjectiveC additions for humans. Ruby style.
MIT License
2.17k stars 190 forks source link

Fix for bug in [NSMutableArray keepIf:] #77

Closed johnno1962 closed 10 years ago

johnno1962 commented 10 years ago

The following test will fail when two adjacent values do not meet the condition as it will skip an element:

NSMutableArray *ma = [NSMutableArray arrayWithObjects:@1, @3, @10, nil];

[ma keepIf:^BOOL(id object) {
    return [object intValue] > 5;
}];

if ( ![ma isEqual:@[@10]] )
       XCTFail(@"fail …

The alternative is to go through the array in reverse order though in a way this is less intuitive.

supermarin commented 10 years ago

@johnno1962 thanks for the contribution. Would you mind writing a test for this?

johnno1962 commented 10 years ago

Test written though it is a separate pull request as I deleted the original fork