views:

60

answers:

1

Hi I want to put this into a function.

NSMutableArray* weekArray = [[NSMutableArray alloc] init];
    [weekArray addObject:@"Before School"];
    [weekArray addObject:[NSString stringWithFormat:@""]];
    [weekArray addObject:[NSString stringWithFormat:@""]];
    [weekArray addObject:@"Break"];
    [weekArray addObject:[NSString stringWithFormat:@""]];
    [weekArray addObject:[NSString stringWithFormat:@""]];
    [weekArray addObject:@"Lunch"];
    [weekArray addObject:[NSString stringWithFormat:@""]];
    [weekArray addObject:[NSString stringWithFormat:@""]];
    [weekArray addObject:@"After School"];
    return weekArray;

I want to be able to call it and when called, replace weekArray with the array I choose. Possible?

+1  A: 

Assuming I understand what you're asking, sure. Here's an example:

NSArray *arrayLikeThat() {
    return [NSMutableArray arrayWithObjects: @"Before School",
                                             [NSString stringWithFormat:@""],
                                             [NSString stringWithFormat:@""],
                                             @"Break",
                                             [NSString stringWithFormat:@""],
                                             [NSString stringWithFormat:@""],
                                             @"Lunch",
                                             [NSString stringWithFormat:@""],
                                             [NSString stringWithFormat:@""],
                                             @"After School",
                                             nil];
}

You can assign the result to any variable you want.

Chuck