I have a validation method by which I analyse whether a particular variable passes a validation criteria.
Here's the code:
-(BOOL)validateFields{
BOOL valid = FALSE;
if (dateEntry != TRUE && saveOrderType != TRUE) {
if (_editRequired==YES) {
if ([[[editedTextField text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:@""]) {
valid = FALSE;
} else {
valid = TRUE;
}
} else {
valid = TRUE;
}
if (_editRegEx) {
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:_editRegEx
options:NSRegularExpressionCaseInsensitive
error:nil];
if ([regex numberOfMatchesInString:[editedTextField text] options:0 range:NSMakeRange(0, [[editedTextField text] length])]==0) {
valid=FALSE;
} else {
valid = TRUE;
}
} else {
valid = TRUE;
}
} else {
valid = TRUE;
}
return valid;
}
I'm getting 3 instances of Value stored to 'valid' is never read
which is strange because eventually, it's returned at the end of the method.
I'm getting it on the first three instances of setting the variable, only on these three:
if (_editRequired==YES) {
if (//checks if the field contains any characters) {
valid = FALSE;
} else {
valid = TRUE;
}
} else {
valid = TRUE;
}
Can anybody help here?
Your if (_editRequired==YES) {}
conditional is completely overridden by the if (_editRegEx) {}
conditional, so none of the assignments inside the former are ever used: valid
is always reassigned in the second conditional.