I have two arrays: one for the total number of fruit consumed in the morning, and the other for the total fruit consumed for that day. What I'd like to do is display the changes/additions made since the morning and store it into a new array whatsNewSinceMorningArray
. So first I need to remove any NSDictionary
objects from both arrays that have the same fruit
and totalNumberConsumed
values (ignoring the comments
), and then I was thinking to just loop through the wholeDayArray
and subtract the totalNumberConsumed
values to find the number consumed since the morning. I've read a couple of threads for removing duplicate NSDictionary
objects inside an array, but I can't figure it out for my particular example. Would appreciate some guidance/point in the right direction.
NSArray *morningArray = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjects:@[@"apples",@"1",@"sour"]
forKeys:@[@"fruit",@"totalNumberConsumed",@"comments"]],
[NSDictionary dictionaryWithObjects:@[@"oranges",@"3",@"sweet"]
forKeys:@[@"fruit",@"totalNumberConsumed",@"comments"]],
[NSDictionary dictionaryWithObjects:@[@"bananas",@"7",@"filling"]
forKeys:@[@"fruit",@"totalNumberConsumed",@"comments"]],nil];
NSArray *wholeDayArray = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjects:@[@"apples",@"2",@"very sour"]
forKeys:@[@"fruit",@"totalNumberConsumed",@"comments"]],
[NSDictionary dictionaryWithObjects:@[@"oranges",@"3",@"slightly bitter"]
forKeys:@[@"fruit",@"totalNumberConsumed",@"comments"]],
[NSDictionary dictionaryWithObjects:@[@"bananas",@"8",@"filling"]
forKeys:@[@"fruit",@"totalNumberConsumed",@"comments"]],
[NSDictionary dictionaryWithObjects:@[@"pineapples",@"1",@"very sweet"]
forKeys:@[@"fruit",@"totalNumberConsumed",@"comments"]],nil];
NSArray *whatsNewSinceMorningArray;
//Should end up with ["apples","1","very sour"],["bananas","1","filling"],["pineapples","1","very sweet"]