gpt4 book ai didi

objective-c - 初始化期间存储到 'myKeyArray' 的值永远不会被读取

转载 作者:行者123 更新时间:2023-12-02 07:05:26 25 4
gpt4 key购买 nike

我收到标记行的“初始化期间存储到‘myKeyArray’的值永远不会被读取”的消息,我不太明白为什么会这样。

- (void)createAndMigrateStatisticalDataForPlayersToV3 {

NSString *playerStatsfilePath = [self dataFilePath5];
NSString *playerDatafilePath = [self dataFilePath6];
NSArray *myKeyArray = [[NSArray alloc]init]; <<<< "Value stored to 'myKeyArray' during its initialization is never read"
NSMutableArray *theObjects = [[NSMutableArray alloc]init]; <<<< "Value stored to 'myKeyArray' during its initialization is never read"

NSFileManager *fileMgr;
fileMgr = [NSFileManager defaultManager];

if ([fileMgr fileExistsAtPath: playerDatafilePath] == YES) {

NSMutableDictionary *gameFileDict = [NSMutableDictionary dictionaryWithContentsOfFile:playerDatafilePath];

NSMutableArray *dataArray = [[NSMutableArray alloc]init];
NSMutableArray *newDataArray = [[NSMutableArray alloc]init];

myKeyArray = [gameFileDict allKeys];

int nrOfKeys = [myKeyArray count];

for (int oo = 0; oo < nrOfKeys; oo++) {
theObjects = [gameFileDict valueForKey:[myKeyArray objectAtIndex:oo]];
[dataArray addObject:[myKeyArray objectAtIndex:oo]]; // Name
[dataArray addObject:[theObjects objectAtIndex:1]]; // # of games played
[dataArray addObject:[theObjects objectAtIndex:2]]; // # correct answers
[dataArray addObject:[theObjects objectAtIndex:3]]; // # questions
[dataArray addObject:[theObjects objectAtIndex:4]]; // # of games won
[dataArray addObject:[theObjects objectAtIndex:5]]; // # of games lost
}

int dataCount = [dataArray count];
float avgNrOfQuestionsPerGame = 0;
float avgNrCorrectAnswersPerGame = 0;
float nrOfQuestions = 0;
float nrOfCorrectAnswers = 0;
float nrOfGamesPerPlayer = 0;
float nrOfMatchesWonPerPlayer = 0;
float nrOfMatchesLostPerPlayer = 0;

for (int oo = 0; oo < dataCount; oo = oo + 6) {

nrOfGamesPerPlayer = [[dataArray objectAtIndex:oo+1]floatValue];
nrOfCorrectAnswers = [[dataArray objectAtIndex:oo+2]floatValue];
nrOfQuestions = [[dataArray objectAtIndex:oo+3]floatValue];
nrOfMatchesWonPerPlayer = [[dataArray objectAtIndex:oo+4]floatValue];
nrOfMatchesLostPerPlayer = [[dataArray objectAtIndex:oo+5]floatValue];

// nrOfGamesPerPlayer = nrOfMatchesLostPerPlayer + nrOfMatchesLostPerPlayer;
avgNrOfQuestionsPerGame = nrOfQuestions / nrOfGamesPerPlayer;
avgNrCorrectAnswersPerGame = nrOfCorrectAnswers / nrOfGamesPerPlayer;

for (int ff = 0; ff < nrOfGamesPerPlayer; ff++) {
[newDataArray addObject:[dataArray objectAtIndex:oo]]; //PlayerName
[newDataArray addObject:[self get_the_Date]]; //set todays date
[newDataArray addObject:[NSNumber numberWithInt:avgNrOfQuestionsPerGame]];
[newDataArray addObject:[NSNumber numberWithInt:avgNrCorrectAnswersPerGame]];


}
}
[newDataArray writeToFile:playerStatsfilePath atomically: TRUE];
}

最佳答案

我会去掉这一行,你不需要初始化它。

//NSArray *myKeyArray = [[NSArray alloc]init];

将此更改为

NSArray *myKeyArray;

如果它是可变的,你只需要分配它。

关于objective-c - 初始化期间存储到 'myKeyArray' 的值永远不会被读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12665081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com