Search code examples
iphoneobjective-cstringint

ObjectiveC Parse Integer from String


I'm trying to extract a string (which contains an integer) from an array and then use it as an int in a function. I'm trying to convert it to a int using intValue.

Here's the code I've been trying.

  NSArray *_returnedArguments = [serverOutput componentsSeparatedByString:@":"];
  [_appDelegate loggedIn:usernameField.text:passwordField.text:(int)[[_returnedArguments objectAtIndex:2] intValue]];

I get this error:

passing argument 3 of 'loggedIn:::' makes pointer from integer without a cast

What's wrong?


Solution

  • I really don't know what was so hard about this question, but I managed to do it this way:

    [myStringContainingInt intValue];

    It should be noted that you can also do:

    myStringContainingInt.intValue;