我有两个数组:一个是早上消耗的水果总数,另一个是当天消耗的水果总数。我想做的是显示从早上以来所做的更改/添加并将其存储到一个新的数组whatsNewSinceMorningArray
中。因此,首先我需要NSDictionary
从两个数组中删除具有相同fruit
和totalNumberConsumed
值的任何对象(忽略comments
),然后我想只是循环遍历wholeDayArray
并减去这些totalNumberConsumed
值以找到从早上开始消耗的数字。我已经阅读了几个线程来删除NSDictionary
数组中的重复对象,但是对于我的特定示例,我无法弄清楚。将不胜感激一些指导/指向正确的方向。
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"]