How can I optimize the if
condition in this snippet? The only one difference is && [self isCurrentPosition:i]
. How can I make it a single if
, including the condition val
?
Note: self
is a category of NSArray
.
- (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:@""];
}
// -----------
}
}