Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1112645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:44:34+00:00 2026-05-17T02:44:34+00:00

i have an if statement comparing two NSStrings, one is user input from a

  • 0

i have an if statement comparing two NSStrings, one is user input from a UITextField the other is a NSString created from random integers between 0-9 inclusive, however the comparison is failing everytime even thought they are the same which is shown in the log from an NSLog call. so can anyone see anything i’m doing wrong in the supplied code?

-(void) generateDecryptionCode{
    codeToConfirm = [NSString stringWithFormat:@"%i%i%i%i%i%i", arc4random()%10, arc4random()%10, arc4random()%10, arc4random()%10, arc4random()%10, arc4random()%10];
    numberToDecrypt.text = codeToConfirm;
}
- (void) decryptTimerFires{
    NSURL *beep = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Beep.aif", [[NSBundle mainBundle] resourcePath]]];
    NSURL *buzz = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Buzz.aif", [[NSBundle mainBundle] resourcePath]]];
        if(decryptTime > 0){
            decryptTime--;
            decryptLabel.text = [NSString stringWithFormat:@"%g",  (float)decryptTime/10];
        if(decryptTime%10 == 0){
            audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:beep error:nil];
            audioPlayer.numberOfLoops = 1;
            [audioPlayer play];
        }
    }
    else{
        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:buzz error:nil];
        audioPlayer.numberOfLoops = 1;
        [audioPlayer play];
        [decryptTimer invalidate];
        decryptTimer = nil;
    }

}
-(void) stopDecrypt{
    NSLog(@"Stop Decrypt");
    [decryptTimer invalidate];
    decryptTimer = nil;

}
-(IBAction)decrypt{
    [self generateDecryptionCode];
    decryptTime = 200;
    decryptTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(decryptTimerFires) userInfo:nil repeats:YES];
    [decryptTimer fire];

}
- (void)dealloc {
    [decryptLabel release];
    [decryptButton release];
    [crackLabel release];
    [crackButton release];
    [numberToCrack release];
    [numberToDecrypt release];
    [audioPlayer release];
    [super dealloc];
}

-(void) enterDecryptKey{
    confirm = [[UIAlertView alloc] initWithTitle:@"Confirm Code" message:@"Please Input The Correct Code:"  delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm Code", nil];
    inputCode = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
    CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60);

    [confirm setTransform:myTransform];
    [inputCode setBackgroundColor:[UIColor whiteColor]];
    [confirm addSubview:inputCode];
    [confirm show];
    [confirm release];
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
   NSLog(@"Enter code:");
    if(buttonIndex == 0){
        [confirm dismissWithClickedButtonIndex:0 animated:YES];
    }
    else if(buttonIndex == 1){
        NSLog(@"Code:%@/User Input:%@",codeToConfirm, inputCode.text);
        NSLog(@"comparing code...");
        if (inputCode.text == codeToConfirm) {
            NSLog(@"Code Correct");
            [self stopCrack];
            [self stopDecrypt];
        }
    }
}

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    [inputCode resignFirstResponder];
    [inputCode removeFromSuperview];  
    [inputCode release];  
}
  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:44:34+00:00Added an answer on May 17, 2026 at 2:44 am

    You should compare the strings with - (BOOL) isEqualToString or - (BOOL) isEqual == will return only true if the two pointer point to the same address

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have sql statement one; select linkscat.id, linkscat.category from linkscat, contentlinks, links where contentlinks.linksid
I have a PHP script which includes one or two other libraries it depends
I have a SQL select statement which is comparing two tables. I am getting
I have the following select statement to get the last login from the user
We have this statement: (SELECT res_bev.bev_id, property_value.name AS priority FROM res_bev, bev_property, property_value WHERE
I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions
Can an if statement have more than one then statements? # this works a
I have a Comparator that checks nulls for the two objects before comparing their
My problem stems from this: VBA (Excel) vs SQL - Comparing values in two
I am trying to compare two integers. One is the row of an NSIndexPath

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.