NSInteger x = [textField.text integerValue];
Cocoa touch code to set NSInteger to number in a text field
-
30-05-2022 - |
Question
I need to set an NSInteger to the number in a text field. And I've googled it and could not find any answer. Does anybody know how to do this
Solution
OTHER TIPS
John C. Daub answer is perfect. I would add this also:
NSInteger x = [[NSNumber numberWithInteger:[field.text integerValue]] integerValue];
The advantage of NSNumber
is that if you want to pass this integer into dicitonary, NSNumber helps.
On the other hand a call to integerValue
would be sufficient.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow