this is my first post here!
How can i optimize the if condition on this snippet?
The only one difference is && [self isCurrentPosition:i]
.
How can made it on a single if, including the condition val
?
- (void) cleanTextfieldExcluding:(int)current checkPosition:(BOOL)val {
for ( int i=0; i<[self count]; i++ ) {
// -----------
if ( val ) { // this IF block is very bad
if ( i != current && [self isCurrentPosition:i] )
[self replaceObjectAtIndex:i withObject:@""];
} else {
if ( i != current )
[self replaceObjectAtIndex:i withObject:@""];
}
// -----------
}
}
Note: self
is a category of NSArray
.
thanks.