needshelp needshelp - 1 year ago 86
iOS Question

Change NSString to int value?

I am having trouble trying to run this test due to an error on the first line of this code that states: Incompatible pointer to integer conversion initializing 'int' with an expression of type 'NSString *'

- (IBAction)Button:(id)sender
int x = TramNumber.text;
if (x < 9)
Tramresult.text = [NSString stringWithFormat:@"lol"];
NSLog (@"x is less than 9!");

Please help. I am on iOS and running xCode 5.1.1 if that helps.

Answer Source

You are representing NSString value wrong.

Use this code sample to solve you're problem:

int x = [TramNumber.text intValue];

To represent int value from you're textfield.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download