2010-09-13 92 views
0

嗨,我想把這個功能。iPhone功能,交換陣列

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; 

我希望能夠把它和調用時,與陣列我選擇更換weekArray。可能?

+0

你能改說/澄清你在問什麼嗎? – kubi 2010-09-13 20:08:14

+0

這不是一個問題,在我看來,與以前發佈的問題沒有什麼不同,已經得到了解答:http://stackoverflow.com/questions/3677488/compress-this-into-a-function – jlehr 2010-09-13 20:12:29

+0

@ jlehr:這裏OP想用一個數組作爲參數,而不是六個對象作爲參數。 – BoltClock 2010-09-13 20:14:53

回答

1

假設我明白你在問什麼,當然。以下是一個示例:

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

您可以將結果分配給您想要的任何變量。