ios - How to Sort an NSArray of UIColor Objects -
i wrote class has property of type uicolor called color. how can sort nsarray containing handful of instances of class color property? have tried code below error: [uicacheddevicergbcolor compare:]: unrecognized selector sent instance. best way sort uicolor objects?
nssortdescriptor *sort = [[nssortdescriptor alloc]initwithkey:@"color" ascending:yes]; array = (nsmutablearray*)[array sortedarrayusingdescriptors:@[sort]];
you need use comparator return wether 1 color greater other.
nssortdescriptor *sort = [[nssortdescriptor alloc]initwithkey:@"color" ascending:yes comparator:^(id obj1, id obj2) { if (do math determine color bestest) { return (nscomparisonresult)nsorderedascending; }else{ return (nscomparisonresult)nsordereddescending; } }];
Comments
Post a Comment