Reputation: 3433
I get an "Expected Identifier" message against the if line. Any ideas why?
if ([inputA.text isEqualToString:@""]) && ([inputB.text <> isEqualToString:@""]) {
c = 1;
}
I'm trying to say it both inputs are empty... I presume there isn't an easier way to say if the text is null in Obj C++?
Upvotes: 0
Views: 1949
Reputation: 90601
An if
statement requires that its condition expression be enclosed in parentheses. You have a compound expression. You've used parentheses around the subexpressions of the logical AND operation (&&), but you haven't surrounded the entire expression in parentheses. (The subexpressions don't actually require parentheses in this case, but they don't hurt.)
Next, you have a random <>
in the second subexpression. What is that doing in there? In some languages that is the "not equal" operator, but a) it's not an operator in C or Objective-C, b) it wouldn't go inside a message-send expression like that, and c) you claim you were trying to check that both inputs are empty, so I wouldn't expect you to try to negate the test for equality with the empty string.
So, fixing just those problems yields:
if ([inputA.text isEqualToString:@""] && [inputB.text isEqualToString:@""]) {
c = 1;
}
That said, pie's answer is good, too. It also works if either of the inputs has a nil
text property, too.
Upvotes: 1