ObjectiveC Parse Integer from String

Christian Stewart picture Christian Stewart · Aug 24, 2010 · Viewed 130.7k times · Source

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?

Answer

Christian Stewart picture Christian Stewart · Aug 25, 2010

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;