0
我在iOS開發是新的,我想寫下以下的最佳方式的場景:如何優化嵌套NSMutableArray代碼的最佳方式?
- (void)configureDataSource {
NSMutableArray *meterUnitArray = [[NSMutableArray alloc] init];
NSMutableArray *meterSubUnitArray = [[NSMutableArray alloc] init];
NSMutableArray *footUnitArray = [[NSMutableArray alloc] init];
NSMutableArray *footSubUnitArray = [[NSMutableArray alloc] init];
self.footArray = [[NSMutableArray alloc] init];
self.meterArray = [[NSMutableArray alloc] init];
for(int i = 0; i <= 99; i++)
{
NSString *str = [NSString stringWithFormat:@"%d Meter", i];
NSString *str1 = [NSString stringWithFormat:@"%d cm", i];
[meterUnitArray addObject:str];
[meterSubUnitArray addObject:str1];
NSString *str2 = [NSString stringWithFormat:@"%d Foot", i];
NSString *str3 = [NSString stringWithFormat:@"%d Inches", i];
[footUnitArray addObject:str2];
[footSubUnitArray addObject:str3];
}
[self.meterArray addObject:meterUnitArray];
[self.meterArray addObject:meterSubUnitArray];
[self.footArray addObject:footUnitArray];
[self.footArray addObject:footSubUnitArray];
}
我怎麼能改進這個代碼?
你想實現什麼? – ajpallares
我認爲這個問題更屬於這裏:http://programmers.stackexchange.com/ – Losiowaty
或甚至更好,在這裏:http://codereview.stackexchange.com/ – Losiowaty