There is an array with objects
NSArray * array = [NSArray arrayWithObjects:@"1", @"2", @"1", @"4", @"8", @"2", @"2", @"1", @"6", @"1", @"4", nil]; The task next is to split this array into smaller arrays with duplicate elements;
Example:
NSArray * array1 = [NSArray arrayWithObjects:@"1", @"1", @"1", @"1", nil]; NSArray * array2 = [NSArray arrayWithObjects:@"2", @"2", @"2", nil]; NSArray * array3 = [NSArray arrayWithObjects:@"4", @"4", nil]; NSArray * array4 = [NSArray arrayWithObjects:@"6", nil]; NSArray * array5 = [NSArray arrayWithObjects:@"8", nil]; p / s I used numbers for example only, in fact objects are compared, and the task is to put identical objects in a separate array.
Implemented through diksheneri
NSString * stringKey = [dictPrice objectForKey:@"product_id"]; if ([[[SingleTone sharedManager] dictBouquets] objectForKey:stringKey]) { NSMutableArray * array = [[[SingleTone sharedManager] dictBouquets] objectForKey:stringKey]; [array addObject:dictPrice]; } else { NSMutableArray * array = [[NSMutableArray alloc] init]; [array addObject:dictPrice]; [[[SingleTone sharedManager] dictBouquets] setValue:array forKey:stringKey]; } But it does not work with an array ... it is necessary to somehow compare the objects of the array not in a loop but in a condition.