Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Possible check before hand if we need to do all the following code
  2. NSArray *uniqueSalesCategoryName = [NSSet setWithArray:[finalBarListArray valueForKeyPath:@"sales_sub_category_name"];
  3. if ([uniqueSalesCategoryName count] == [finalBarListArray count])
  4. {
  5.     //There is no need to do the following code, no duplicate.
  6. }
  7.  
  8. NSMutableArray *barListWithUnicity = [[NSMutableArray alloc] init];
  9. NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
  10. for (BarCodeSKULists *aBarCodeSKULists in finalBarListArray)
  11. {
  12.     NSMutableArray *array = nil;
  13.     array = [keepDict objectForKey:[aBarCodeSKULists sales_sub_category_name]];
  14.     if (!array)
  15.     {
  16.         array = [[NSMutableArray alloc] init];
  17.         [keepDict setObject:array forKey:[aBarCodeSKULists sales_sub_category_name]];
  18.     }
  19.     [array addObject:aBarCodeSKULists];
  20. }
  21. for (NSString *aCategoryName in keepDict)
  22. {
  23.     NSMutableArray *array = keepDict[aCategoryName];
  24.     BarCodeSKULists *barCodeSKUList = [array firstObject];
  25.     if ([array count] > 1) //We have to combine
  26.     {
  27.         [barCodeSKUList combineWithOthers:[array subarrayWithRange:NSMakeRange(1, [array count]-1)]];
  28.     }
  29.     [barListWithUnicity addObject:barCodeSKUList];
  30. }
  31.  
  32. //Use barListWithUnicity to do what you need
  33.  
  34.  
  35. //Method for BarCodeSKUList
  36. -(void)combineWithOthers:(NSArray *)othersBarCodeSKUList
  37. {
  38.     //I assumed there is no check of unicity here, but you can add one if you want
  39.     for (BarCodeSKUList *anotherBarCodeSKUList in othersBarCodeSKUList)
  40.     {
  41.         [[self arrayBarCodeSKUList] addObjectFromArray:[[anotherBarCodeSKUList arrayBarCodeSKUList]];
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement