I have copied the code in question from this page below.
Why do we have the if(error) statement inside of if(match). Won't error always be a valid object? I see that it is NULL, which makes me also ask, when it would be anything other than NULL?
Why not just, which works as well...
Why do we have the if(error) statement inside of if(match). Won't error always be a valid object? I see that it is NULL, which makes me also ask, when it would be anything other than NULL?
Code:
- (BOOL)isPartialStringValid:(NSString*)partial
newEditingString:(NSString**)newString
errorDescription:(NSString**)error
{
//Zero-length strings are ok
if([partial length] == 0){
return YES;
}
NSString *match =[self firstColorKeyForPartialString:partial];
if(match){
return YES;
} else {
if(error){ //WHY IS THIS IF STATEMENT HERE
*error = @"No such color";
}
return NO;
}
}
Why not just, which works as well...
Code:
- (BOOL)isPartialStringValid:(NSString*)partial
newEditingString:(NSString**)newString
errorDescription:(NSString**)error
{
//Zero-length strings are ok
if([partial length] == 0){
return YES;
}
NSString *match =[self firstColorKeyForPartialString:partial];
if(match){
return YES;
} else {
*error = @"No such color";
return NO;
}
}