开发者

iPhone Function, Swap Arrays

开发者 https://www.devze.com 2023-01-15 19:53 出处:网络
Hi I want to put this into a function. NSMutableArray* weekArray = [[NSMutableArray alloc] init]; [weekArray addObject:@\"Before School\"];

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

精彩评论

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