PDA

View Full Version : Extract Integer from UITextField?




parkov
Aug 8, 2008, 05:16 PM
Newbie question here.

How do I extract an int value from a UITextField (textKey)? I have the following:

NSInteger inputKey = textKey.text;

Which gives me this warning:

warning: initialization makes integer from pointer without a cast

Thanks!



sfwalter
Aug 8, 2008, 05:34 PM
Newbie question here.

How do I extract an int value from a UITextField (textKey)? I have the following:

NSInteger inputKey = textKey.text;

Which gives me this warning:

warning: initialization makes integer from pointer without a cast

Thanks!

You can't take an object and assign it to a primitive. NSInteger is really just a typedef of int. You can do this:

NSInteger theInteger = [textKey.text intValue];

parkov
Aug 9, 2008, 09:46 AM
You can't take an object and assign it to a primitive. NSInteger is really just a typedef of int. You can do this:

NSInteger theInteger = [textKey.text intValue];

Thanks. Can you go in the other direction, or do you have to use methods for those as well? For example:

creating an NSMutableArray from ints

creating an NSString from chars