我已經編寫了一個類方法,用於轉換文本文件中的列數據並返回數組數組...只有它返回EMPTY數組的EMPTY數組。返回空數組的類方法
+(NSArray *) initArrayWithFileContents:(NSString *) theFilePath
{
NSString *theContents = [self loadFile:theFilePath];
NSArray *theParagraphs = [self getParagraphs:theContents];
NSMutableArray *teamData = [[NSMutableArray alloc] init]; // array of team data
NSMutableArray *leagueData = [[NSMutableArray alloc] init]; // array of arrays
// set up number formatters for getting numbers from strings
NSNumberFormatter *numberStyle = [[NSNumberFormatter alloc] init];
NSNumberFormatter *positiveNumberStyle = [[NSNumberFormatter alloc] init];
[numberStyle setNumberStyle:NSNumberFormatterDecimalStyle];
[positiveNumberStyle setNumberStyle:NSNumberFormatterDecimalStyle];
[positiveNumberStyle setPositiveFormat:@"'+'#"];
// set up a date and time formatter for getting time data from strings
NSDateFormatter *timeStyle = [[NSDateFormatter alloc] init];
[timeStyle setDateStyle:NSDateFormatterNoStyle];
[timeStyle setDateFormat:@" mm:ss"];
for (NSString *currentParagraph in theParagraphs)
{
NSArray *currentTeam = [self getcolumnarData:currentParagraph]; // get an array of strings
for (NSString *currentItem in currentTeam)
{
NSNumber *currentStat = [numberStyle numberFromString:currentItem];
if (currentStat != Nil) {
[teamData addObject:currentStat]; // number found
} else {
currentStat = [positiveNumberStyle numberFromString:currentItem];
if (currentStat != Nil) {
[teamData addObject:currentStat]; // number with '+' sign found
} else {
NSDate *currentTime = [timeStyle dateFromString:currentItem];
if (currentTime != Nil) {
NSNumber *theSeconds = [self calculateSeconds: currentTime];
[teamData addObject:theSeconds]; // time found
} else {
[teamData addObject:currentItem]; // string found
}
}
}
}
[leagueData addObject:teamData]; // add child array to end of parent array
[teamData removeAllObjects]; // reset child array
}
NSArray *dataToReturn = [NSArray arrayWithArray:leagueData]; // convert to NSArray to return
return dataToReturn;
}
以我的調試工作我已驗證被添加到所述teamData
數組的末尾或者一個NSString或NSNumber的但添加teamData
到leagueData
當加入一個空對象。我錯過了什麼?
由於提前, 布拉德
空數組的空數組沒有意義,第一個數組不是空的,因爲它包含一堆空數組。 –