0

PLIST に保存した配列を読み込み、要素を変更して、PLIST に保存したいと考えています。

私の簡単なコードは次のとおりです。

NSArray *mathScoreArray;
NSNumber *score1 = [NSNumber numberWithInteger:score];
NSMutableArray *scoreArray1 = [[NSArray arrayWithArray:mathScoreArray] init];
[scoreArray1 replaceObjectAtIndex:4 withObject:score1];
[dictionary setObject:scoreArray1 forKey :@"mathScoreArray"];
[dictionary writeToFile:finalPath atomically:YES];

配列を変更するための「replaceObjectAtIndex」でエラーが発生します。これどうやってするの??

参考までに、私の plist は次のようになります。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>mathQues</key>
    <integer>1</integer>
    <key>mathScore</key>
    <integer>0</integer>
    <key>mathScoreArray</key>
    <array>
        <integer>10</integer>
        <integer>20</integer>
        <integer>30</integer>
        <integer>40</integer>
        <integer>50</integer>
    </array>
</dict>
</plist>

問題を拡張すると、最終的には配列を 1 つ右にシフトし、[スタックのように] 新しい着信値を一番上に格納したいと思います。

ポインタをありがとう。ユーザー

4

1 に答える 1

3

この行を変更します。

    NSMutableArray *scoreArray1 = [[NSArray arrayWithArray:mathScoreArray] init];
// you need NSMutableArray, not NSArray ^
//                           you already got an array, no need to initialize ^

に:

    NSMutableArray *scoreArray1 = [NSMutableArray arrayWithArray:mathScoreArray];

また、あなたのコードには、そもそも をどのように読んだかの兆候はありませんNSArray

于 2012-05-01T04:25:28.290 に答える