-2

I am getting this error on my if statement.

CODE:

-(IBAction)login:(id)sender
{

    NSString *correctUser = @"money";
    NSString *correctPassword = @"ilovemoney";

    if ((usernameTextField.text == correctUser)==YES && (passwordTextField.text = correctPassword)==YES) //error is on the beginning of this if statement.
    {
        [self performSegueWithIdentifier:@"oneTransition" sender:sender];
    }

}
1
  • What are the types of usernameTextField.text and YES? Commented May 24, 2014 at 16:58

1 Answer 1

4

There are a bunch of problems here.

  • You're using = instead of == in your second test, which is assignment, not comparison; this is why you're getting the warning.

  • Comparing strings with == doesn't do what you want. You should use [usernameTextField.text isEqual:correctUser], for example.

  • You should never compare something to YES as in == YES. So, instead of if (something == YES) just say if (something).

Sign up to request clarification or add additional context in comments.

3 Comments

On that third point, you should always use if( ((((a == b) == YES) == YES) == YES) == YES ). It's the only way to be sure.
Yes, thanks, @Dave, I had forgotten to mention that.
Thanks. that worked, I used the isEqual.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.