私のiPhoneアプリはplistファイルの辞書にキーと値のペアを書き込みます。私は基本的に彼らがゲームをプレイするときにユーザーのスコアを保存しています。これはすばらしくて素敵ですが、アプリを実行して新しいスコアを得るたびに、新しい値が古い値に保存されます。ファイルを書き換えるのではなく、ユーザーがアプリにアクセスするたびにplistに情報を追加するにはどうすればよいですか?私は最新のものだけでなく、すべてのスコアを保持したい。アプリを実行するたびにplistに追加情報を保存しますか? (iPhone)
コード:
-(void)recordValues:(id)sender {
//read "propertyList.plist" from application bundle
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path
stringByAppendingPathComponent:@"propertyList.plist"];
dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath];
//create an NSNumber object containing the
//float value userScore and add it as 'score' to the dictionary.
NSNumber *number=[NSNumber numberWithFloat:userScore];
[dictionary setObject:number forKey:@"score"];
//dump the contents of the dictionary to the console
for (id key in dictionary) {
NSLog(@"memory: key=%@, value=%@", key, [dictionary
objectForKey:key]);
}
//write xml representation of dictionary to a file
[dictionary writeToFile:@"/Users/rthomas/Sites/propertyList.plist" atomically:NO];
}
ああ。だからそれは配列です。本当にありがとう! – Evelyn
私はまだ問題があります。私は辞書の配列を作成する必要があると言っていますか? – Evelyn
いいえ、キーは数字の代わりに数字の配列にしてください、配列はオブジェクトのリストです... mのように任意の数字をudのように置くことができます...あなたはそれを可変にしたいです配列を追加して削除することができます。 – Daniel