How to reduce the set of colors in Objective-C

I’m very, very new to Objective-C (this is for a React Native app), and I am trying to pare down a list of colors and remove duplicates.

I’ve got this so far:

... code related to pulling pixels from an image

float flexibility = 2;
float range = 60;

NSMutableArray * colors = [NSMutableArray new];

float x = 0;
float y = 0;
for (int n = 0; n<(width*height); n++){

  int index = (bytesPerRow * y) + x * bytesPerPixel;
  int red   = rawData[index];
  int green = rawData[index + 1];
  int blue  = rawData[index + 2];
  int alpha = rawData[index + 3];
  NSArray * a = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%i",red],[NSString stringWithFormat:@"%i",green],[NSString stringWithFormat:@"%i",blue],[NSString stringWithFormat:@"%i",alpha], nil];
  [colors addObject:a];

  y++;
  if (y==height){
    y=0;
    x++;
  }
}
free(rawData);

Now the script I am basing this off of has some code to pare down the list:

NSMutableDictionary * colourCounter = [NSMutableDictionary new];

//count the occurences in the array
NSCountedSet *countedSet = [[NSCountedSet alloc] initWithArray:colors];
for (NSString *item in countedSet) {
    NSUInteger count = [countedSet countForObject:item];
    [colourCounter setValue:[NSNumber numberWithInteger:count] forKey:item];
}

//sort keys highest occurrence to lowest
NSArray *orderedKeys = [colourCounter keysSortedByValueUsingComparator:^NSComparisonResult(id obj1, id obj2){
    return [obj2 compare:obj1];
}];

//checks if the colour is similar to another one already included
NSMutableArray * ranges = [NSMutableArray new];
for (NSString * key in orderedKeys){
    NSArray * rgb = [key componentsSeparatedByString:@","];
    int r = [rgb[0] intValue];
    int g = [rgb[1] intValue];
    int b = [rgb[2] intValue];
    bool exclude = false;
    for (NSString * ranged_key in ranges){
        NSArray * ranged_rgb = [ranged_key componentsSeparatedByString:@","];

        int ranged_r = [ranged_rgb[0] intValue];
        int ranged_g = [ranged_rgb[1] intValue];
        int ranged_b = [ranged_rgb[2] intValue];

        if (r>= ranged_r-range && r<= ranged_r+range){
            if (g>= ranged_g-range && g<= ranged_g+range){
                if (b>= ranged_b-range && b<= ranged_b+range){
                    exclude = true;
                }
            }
        }
    }

    if (!exclude){ [ranges addObject:key]; }
}

//return ranges array here if you just want the ordered colours high to low
NSMutableArray * colourArray = [NSMutableArray new];
for (NSString * key in ranges){
    NSArray * rgb = [key componentsSeparatedByString:@","];
    float r = [rgb[0] floatValue];
    float g = [rgb[1] floatValue];
    float b = [rgb[2] floatValue];
    UIColor * colour = [UIColor colorWithRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f];
    [colourArray addObject:colour];
}

//if you just want an array of images of most common to least, return here
//return [NSDictionary dictionaryWithObject:colourArray forKey:@"colours"];

I ultimately want to return this colourArray (the original library uses colour, I use color, so you’ll sometimes see one or the other spelling – I’ll probably standardize it to color when finished).

However, whenever I use this code, RN generates an error:

Unrecognized selector

As far as I can tell, this is due to calling a function that doesn’t exist? Is there something I am missing here, or calling incorrectly?

Source: React natvie