Note that there are some explanatory texts on larger screens.

plurals
  1. POApp crashes when comparing two strings of type NSString
    text
    copied!<p>I just just "isEqualToString:" to compare to strings in my iPhone App. The var value is a text and "subInput" is a string out of a text field. Till now everything went well, when the first character of the input field has been the same as the first character of the text. But when they don't fit, the App crashes. When typing in a wrong character after starting well, everything is ok.</p> <pre><code>subInput = [[NSString alloc] initWithString:[theInput text]]; compare = [[NSString alloc] initWithString:[value substringToIndex:subInput.length]]; if([subInput isEqualToString:compare]){ //Here the app stops working </code></pre> <p>I also tried to compare the result with "!= 0" or "!= nil" but also didn't work.</p> <hr> <p>ADDITIONAL CODE </p> <pre><code>if([subInput isEqualToString:compare] != nil){ NSLog(@"any"); if([subInput isEqualToString:value]){ NSLog(@"other"); NSLog(@"well done"); theInput.enabled = FALSE; lastValid = theInput.text; theMessage.backgroundColor = [UIColor orangeColor]; theMessage.text = @"WELL DONE!!!!"; theMessage.textColor = [UIColor blackColor]; //save points for remaining seconds score += seconds*10; //invalidate counter when typed in all text correct [count invalidate]; [self newTimer:3.0]; }else{ if(theInput.text.length &gt;= range){ NSLog(@"SCROLLEN"); [theText setSelectedRange:NSMakeRange(range, addRange)]; range += addRange; } //NSLog(@"String is ok"); //self.view.backgroundColor = [UIColor blackColor]; lastValid = theInput.text; theMessage.backgroundColor = [UIColor greenColor]; theMessage.text = @"GO GO GO"; theMessage.textColor = [UIColor whiteColor]; } } else{ //incrementing the fail var for every wrong letter fails++; theInput.text = [@"" stringByAppendingString:lastValid]; theMessage.backgroundColor = [UIColor redColor]; theMessage.text = @"WRONG CHARACTER!!!"; theMessage.textColor = [UIColor whiteColor]; if (grade &gt;= 2) { seconds -= 2; } if(grade == 3){ int actual = theInput.text.length; actual--; NSString *shorterString = [theInput.text substringToIndex:actual]; lastValid = shorterString; theInput.text = shorterString; } //change bg-color to iritate the player self.view.backgroundColor = [UIColor colorWithRed:[self r:255]/255.0 green:[self r:255]/255.0 blue:[self r:255]/255.0 alpha:1]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload