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

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -