필자는 텍스트 파일에서 열 데이터를 변환하고 배열 배열을 반환하는 클래스 메서드를 작성했습니다 ... 비어있는 배열의 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;
}
나는있는 NSString 또는의 NSNumber 중 하나가 teamData
배열의 마지막에 추가되고 있지만 leagueData
에 teamData
를 추가 할 때 빈 개체가 추가되었는지 확인했습니다. 내가 뭘 놓치고 있니? 사전에
감사합니다, 루프에 브래드
빈 배열의 빈 배열은 의미가 없습니다. 첫 번째 배열에는 빈 배열이 포함되어 있으므로 첫 번째 배열은 비어 있지 않습니다. –