开发者

iPhone Function, Swap Arrays

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:@""]];
   开发者_StackOverflow社区 [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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜