Extract Integer from UITextField?

Discussion in 'iOS Programming' started by parkov, Aug 8, 2008.

  1. parkov macrumors newbie

    Aug 29, 2005
    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​

  2. sfwalter macrumors 68000


    Jan 6, 2004
    Dallas Texas
    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];
  3. parkov thread starter macrumors newbie

    Aug 29, 2005
    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

Share This Page