iPhone: How to convert normal NSArray into an NSArray containing NSNumber values?

273 Views Asked by At

In my iPhone app, I am using an array which contains the values like shown below:

A:{
  1000,
  2000,
  -1000,
   4000
  }

Now I want to convert this to the array shown below.

NSArray *A = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:1000],[NSNumber numberWithInt:2000],[NSNumber numberWithInt:-1000],[NSNumber numberWithInt:4000],nil];

How can I do that?

Edit:

Also I cannot use the value of Array A:{1000,2000,-1000,4000} to directly pass it into the NSNumber numberWithInt method, because it takes these values as NSString and not integers.

1

There are 1 best solutions below

0
On BEST ANSWER

regarding to another question I saw from you I'm guessing those values are NSStrings

then use something like this.

NSMutableArray *array = [NSMutableArray array];
for (NSString *numberString in numberStringArray) {
    [array addObject:[NSNumber numberWithInteger:[numberString integerValue]]];
}

and to be honest I think you should invest more time for the basics before you try to make use of core-plot