我有两个阵列:一个用于早上消耗的水果总数,另一个用于当天消耗的总水果。我想做的是显示自上午以来所做的更改/添加,并将其存储到新的数组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"]