Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn NSString into integer

Sorry guys, I'm a noob. I know that some languages support type casting, but when I tried to do that here it failed, miserably. I've got an UITextField with number only pad, so I'm only getting numbers, and I need the output from that in my int, diff. Here's what I tried:

NSString *outputNumber = [NSString stringWithFormat:@"%d", [textBox.text]]; 
diff = [outputNumber intValue]; //Not so much

What happens is my diff goes to some incredibly high number instead of the single digets I tested with. Any help I could get is great. Thanks :)

like image 914
SeniorShizzle Avatar asked Jul 01 '10 09:07

SeniorShizzle


1 Answers

Why are you using [ ] around textBox.text? And you dont need temporary outputNumber string .

Try this :

diff = [textBox.text intValue];
like image 196
taskinoor Avatar answered Sep 21 '22 13:09

taskinoor