I have been scratching my head most afternoon on this so I thought I would now ask.
The app works but for some reason as I add new client entries the previous ones are being written over by the new one. I am storing some client records in an NSMutableDict (name, job, money and so on.) Then I am storing each dict into an NSMutableArray 1 Dict per index.
I am using the itemsToSave method to gather all the elements and default values to store in the mutable dict. Then in the writePlist method I am adding the dict to the array and adding a number to the 0 index of that array. For some reason when I add new entries all the previous ones get rewritten to the latest information from the last dict entered?
The app works but for some reason as I add new client entries the previous ones are being written over by the new one. I am storing some client records in an NSMutableDict (name, job, money and so on.) Then I am storing each dict into an NSMutableArray 1 Dict per index.
I am using the itemsToSave method to gather all the elements and default values to store in the mutable dict. Then in the writePlist method I am adding the dict to the array and adding a number to the 0 index of that array. For some reason when I add new entries all the previous ones get rewritten to the latest information from the last dict entered?
Code:
- (void)writePlist{
NSString *aNumber = [NSString stringWithFormat:@"%d", clientContentArray.count];
[clientContentArray replaceObjectAtIndex:0 withObject: aNumber];
[clientContentArray addObject:clientInformation]; //add dict to array
[clientContentArray writeToFile:[self dataFilePath] atomically:YES]; //save to plist
NSLog(@"The exporting array has %@", clientContentArray); //display content to screen
}
- (void)itemsToSave{
if (clientInformation) {
[clientInformation setValue:theClientName forKey:@"client"]; //Bellow gathers the info and adds it to the MutableDict
[clientInformation setValue:theJobName forKey:@"job"];
[clientInformation setValue:nameCombind forKey:@"tableViewID"];
[clientInformation setValue:@"0.00" forKey:@"amount"];
[clientInformation setValue:@"Add Note..." forKey:@"note"];
NSLog(@"Items that are being saved" );
for(NSString *aKey in clientInformation){
NSLog(aKey);
NSLog([clientInformation valueForKey:aKey]); //writes out what is in the NSMutableDict.
}
}
else
NSLog(@"There is not client Information Dict");
}