从两个单独的数组中删除常见的NSDictionary对象

时间:2013-09-06 12:13:04

标签: ios objective-c arrays nsdictionary

我有两个阵列:一个用于早上消耗的水果总数,另一个用于当天消耗的总水果。我想做的是显示自上午以来所做的更改/添加,并将其存储到新的数组whatsNewSinceMorningArray中。首先,我需要从两个具有相同NSDictionaryfruit值的数组中删除任何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"]

0 个答案:

没有答案