Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Possible check before hand if we need to do all the following code
- NSArray *uniqueSalesCategoryName = [NSSet setWithArray:[finalBarListArray valueForKeyPath:@"sales_sub_category_name"];
- if ([uniqueSalesCategoryName count] == [finalBarListArray count])
- {
- //There is no need to do the following code, no duplicate.
- }
- NSMutableArray *barListWithUnicity = [[NSMutableArray alloc] init];
- NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
- for (BarCodeSKULists *aBarCodeSKULists in finalBarListArray)
- {
- NSMutableArray *array = nil;
- array = [keepDict objectForKey:[aBarCodeSKULists sales_sub_category_name]];
- if (!array)
- {
- array = [[NSMutableArray alloc] init];
- [keepDict setObject:array forKey:[aBarCodeSKULists sales_sub_category_name]];
- }
- [array addObject:aBarCodeSKULists];
- }
- for (NSString *aCategoryName in keepDict)
- {
- NSMutableArray *array = keepDict[aCategoryName];
- BarCodeSKULists *barCodeSKUList = [array firstObject];
- if ([array count] > 1) //We have to combine
- {
- [barCodeSKUList combineWithOthers:[array subarrayWithRange:NSMakeRange(1, [array count]-1)]];
- }
- [barListWithUnicity addObject:barCodeSKUList];
- }
- //Use barListWithUnicity to do what you need
- //Method for BarCodeSKUList
- -(void)combineWithOthers:(NSArray *)othersBarCodeSKUList
- {
- //I assumed there is no check of unicity here, but you can add one if you want
- for (BarCodeSKUList *anotherBarCodeSKUList in othersBarCodeSKUList)
- {
- [[self arrayBarCodeSKUList] addObjectFromArray:[[anotherBarCodeSKUList arrayBarCodeSKUList]];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement