0

I have this piece of code:

    if (email.text == emailComfirm.text) {
        UIAlertView *emailAllertView = [[UIAlertView alloc] initWithTitle:@"Succes" message:@"Yaaay, je kan nu gebuik gaan maken van Vogelspotter." delegate:self cancelButtonTitle:@"Direct aanmelden" otherButtonTitles: nil];
        [emailAllertView show];
        // Doing some other code here
        [self dismissModalViewControllerAnimated:YES];
    }else{
        NSLog(@"email: %@", email.text);
        NSLog(@"email: %@", emailComfirm.text);

        UIAlertView *emailAllertView = [[UIAlertView alloc] initWithTitle:@"Foutmelding" message:@"De opgegeven email adressen komen niet met alkaar overeen" delegate:self cancelButtonTitle:@"Probeer het nog eens" otherButtonTitles: nil];
        [emailAllertView show];
    }

somehow, no moather wath i type in the textfiels, the is statment always goes to the else, if i enter ee/ee or ee/ff. Can someone tell me what i'm doing wrong?

tnx in advance.

Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
Roeliee
  • 221
  • 2
  • 14
  • possible duplicate of [Why is this code not recognising the NSString as being equal?](http://stackoverflow.com/questions/8625936/), [Comparing strings in Cocoa](http://stackoverflow.com/questions/881335/), [Comparison of two strings fails](http://stackoverflow.com/questions/9322457/), [Understanding `NSString` comparison in ObjC](http://stackoverflow.com/questions/3703554/) – jscs Sep 18 '12 at 19:21
  • Tnx. this did fixed the problem – Roeliee Sep 18 '12 at 19:24

1 Answers1

2

You want to use [email.text isEqualToString:emailComfirm.text] to compare the contents of 2 NSString* objects. using == will compare the addresses of the 2 objects, not the contents of the objects. This is how pointers work How do pointer to pointers work in C?

Community
  • 1
  • 1
Kyle
  • 434
  • 2
  • 10