0

plist ファイルを読み取るためのクラス メソッドを作成しましたが、正常に動作します。ARCで変更したところ、クラスは次のようになりました。

+ (NSDictionary *)readPlistDic:(NSString*)filePlist
{
    NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filePath = [[NSString alloc] initWithString:[[documentsDirectoryPath stringByAppendingPathComponent:filePlist]stringByAppendingPathExtension:@"plist"]];
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSString *startPath = [[path stringByAppendingPathComponent:filePlist]stringByAppendingPathExtension:@"plist"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
        if([[NSDictionary dictionaryWithContentsOfFile:startPath] writeToFile:filePath atomically:NO])
            NSLog(@"File dei profili Copiato nell App DocumentsDirectory\n\n");
        else
            NSLog(@"Errore durante la copia in DocumentsDirectory\n\n");
    }
    NSDictionary *dicReturn = [[NSDictionary alloc] initWithContentsOfFile:filePath];
    return dicReturn;
#warning    return [NSDictionary dictionaryWithContentsOfFile:filePath];
}

動作しますが、リークが発生します

ここに画像の説明を入力

私が間違っているのは何ですか?なにか提案を?ありがとう!

更新 私はここに plist を書きます:

NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:[ReadWritePlistNew readPlistDic:@"PartitaDefault"]];

    NSDate *dataOggi = [NSDate date];
    [dic setValue:dataOggi forKey:Data_Partita];

    NSNumber *idPartitaNum = [NSNumber numberWithInt:ultimoID+1];
    [dic setValue:idPartitaNum forKey:ID_Partita];


    NSArray *salvaGioc = [NSArray arrayWithObjects:ID_GIOCATORE_NORD,ID_GIOCATORE_SUD,ID_GIOCATORE_EST,ID_GIOCATORE_OVEST, nil];
    for (int i=0; i<4; i++) {
        [dic setValue:[NSNumber numberWithInt:[[[self.players objectAtIndex:i] objectForKey:defID_Player] intValue]] forKey:[salvaGioc objectAtIndex:i]];
    }

    NSNumber *numGiocatori = [NSNumber numberWithInt:numeroGiocatori];
    [dic setValue:numGiocatori forKey:GIOCATORI_NUM];
    [dic setValue:[NSNumber numberWithInt:tavoloNumero]    forKey:TAVOLO_NUMERO];


    [dic setValue:[NSNumber numberWithBool:isEXP] forKey:EXP_MODE];

    [dic setValue:[NSNumber numberWithBool:isVPAttivoLocal] forKey:VictoryPointAttivo];

    if (isVPAttivoLocal) {
        [dic setValue:[NSNumber numberWithInt:numeroSmazzateIndex] forKey:NumeroSmazzateIndex];
    }
//GPS#warning salvare gps
    //NSLog(@"isCustomVP_Local  %@",isCustomVP_Local ? @"Attivo":@"Non attivo");
    [dic setValue:[NSNumber numberWithBool:isCustomVP_Local] forKey:ISVP_CUSTOM];
    [dic setValue:[NSString stringWithFormat:@"%d",puntiMax] forKey:PUNTI_FINE_PARTITA];


    //salva tutto sul plist database
    NSMutableDictionary *dicOld = [[NSMutableDictionary alloc] initWithDictionary:[ReadWritePlistNew readPlistDic:@"PartiteDB"]];
    NSMutableArray *arrToSave = [[NSMutableArray alloc] initWithArray:[dicOld objectForKey:@"Partite"]];
    //NSLog(@"dic: %@",dic);
    [arrToSave addObject:dic];
    [dicOld setValue:arrToSave forKey:@"Partite"];
    [ReadWritePlistNew writeToPlist:@"PartiteDB" dic:dicOld];

[ReadWritePlistNew writeToPlist:]:

+ (void)writeToPlist:(NSString*)filePlist arr:(NSArray*)arr
{
    NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filePath = [[documentsDirectoryPath stringByAppendingPathComponent:filePlist]stringByAppendingPathExtension:@"plist"];
    [arr writeToFile:filePath atomically:YES];

}
4

0 に答える 0