I’m trying out some basic Objective-C iPhone coding and I’m trying to compare a number in a UITextField in an if statement.
if (UITextField.text == @"1") {
doSomething
}
I think I have to convert the number in the UITextField to something that can be compared with the 1, but I’m not sure what or how.
Could someone point me in the right direction?
You can do it in one of two ways:
The better way would be to convert the UITextField text to an integer value, using the
NSString function -(int)intValue;As in:
Alternatively, you can compare two strings, but you have to use a string comparison function, not equals, becuase you’re trying to compare the text of the string, not the pointer.