Use this method to save the dictionary;
-(void)saveDefaults:(int)historyCount{
NSDictionary *history1 = [NSDictionary dictionary]; //You already have this dictionary
NSString *historyKey = [NSString stringWithFormat:@"history%d",historyCount];
[[NSUserDefaults standardUserDefaults] setObject:history1 forKey:historyKey];
}
So your code might look somewhat like this;
self.historyCount =1;
[user runTest]; //first run
[user saveDefaults:self.historyCount];
self.historyCount++;
[user runTest];
[user saveDefaults:self.historyCount];
self.historyCount++;
and so on..
If you want multiple history dictionary objects for the same user then you can store the group of history objects as an array (use index to access the history objects) or you could use a dictionary with key like @"history1"
and value, the history1
dictionary. You can generate new keys like shown above.
But if you have multiple users and many history objects for each user , it might get hard to keep track of. Instead you can use core-data for object persistence/management.