I have made a custom keyboard in my app. When user presses spacebar, this code runs:
NSString *lastChar = [myTextField.text substringFromIndex:[myTextField.text length] - 1];
NSLog(@"lastChar is `%@`", lastChar);
if (lastChar != @" ")
{
NSString *currentString = [NSString stringWithFormat:@"%@ ", myTextField.text];
[myTextField setText:currentString];
}
And I make a check, if last symbol that user used was space
, he won't be able to use it again
(no need in my case). However, the code under the if statement
still runing. So I've made a check with NSLog
, and even if the last char was space
, the code under the if statement
executes. How does it happen?
Can somebody point me on my foolish mistake?
Thanks in advance.
UPDATE: Sorry, I always forget how to compare strings in Objective-C, I've already flagged the question, thank you everyone for your anwsers.