Link to home
Create AccountLog in
Avatar of Member_2_4548968
Member_2_4548968

asked on

Add integers to NSMutableArray

Hi,

I simply want to fill a picker component with 100 integers. Is this the best way to fill the picker string array with integers:

        NSMutableArray *yearArray = [[NSMutableArray alloc] init];

      for (unsigned int i = 0; i < 101; ++i) {
            [yearArray addObject:[NSString stringWithFormat:@"%d", i]];
      }
      
    self.years = yearArray;
    [yearArray release];

Or is there a better way to add integers to an NSMutableArray?
ASKER CERTIFIED SOLUTION
Avatar of mad_mac
mad_mac

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of victornegri
victornegri

Unless you're going to be doing manipulation on the array (i.e. sorting, adding, subtracting, etc) prior to pushing it into the picker, your initial solution is probably best since if you used NSNumber, you'd eventually have to convert the NSNumber to an NSString so it can be set as the title for the picker row. Just one less step.