objective c - Sort NSMutableArray Of multiple Objects without keys -
i have nsmutablearray of objects, below struct:
//object @ index locations { nsstring* address; nsstring* state; nsnumber* distance; } i have 10000 object above structure in nsmutablearray. how order array locations in order nsnumber distance?
i tried this:
lowtohigh = [nssortdescriptor sortdescriptorwithkey:@"distance" ascending:yes]; [locationarray sortusingdescriptors:[nsarray arraywithobject:lowtohigh]]; is using sortdescriptorwithkey:@"distance" wrong? since distance isn't key, nsnumber* distance.
edit in header @property (strong, nonatomic)nsnumber* _distance; , @synthesize _distance = distance; in methods file in locationobjects.* object class. import in current class doing sorting. issue? how import locationobjects* locobj = [[locationobjects alloc] init];
this use:
nssortdescriptor *lowtohigh = [[nssortdescriptor alloc] initwithkey:@"distance" ascending:yes]; nsarray *mysortdescriptors = [nsarray arraywithobject:lowtohigh]; nsarray *sortedarray = [locationarray sortedarrayusingdescriptors:mysortdescriptors];
Comments
Post a Comment