Reputation: 50722
I have a textfield in my app, whre the user can enter any number (I have set to Number pad) I want to store this as an integer in a variable I am writing
int numOfYears = [numOfYearsFld text];
But for some reason it is taking it incorrectly e.g. if user enters 10, it taakes as 10214475
Am I doing something wrong ?
Upvotes: 0
Views: 153
Reputation: 6405
Try:
int numOfYears = [[numOfYearsFid text] intValue];
or, preferably
NSInteger numOfYears = [[numOfYearsFid text] integerValue];
intValue
returns an int
and integerValue
returns an NSInteger
.
Upvotes: 0
Reputation: 4752
intValue
returns an int
.
integerValue
returns an NSInteger
.
NSInteger numOfYears = [[numOfYearsFld text] integerValue];
Upvotes: 1
Reputation: 8759
[numOfYearsFld text] will be a NSString*. Try:
int numOfYears = [[numOfYearsFld text] intValue];
Upvotes: 1