Tag: des style ar color using SP strong on log
Nssortdescriptor Specifies the properties of the object used to sort the object array.
If the employee object needs to be sorted by name, the following descriptor is generated
Nssortdescriptor *descriptor = [Nssortdescriptor sortdescriptorwithkey:name Ascending:yes];
If you need more than one sort, such as sort by name first, then by date of entry. Then create a two descriptor
Nssortdescriptor *descriptor = [Nssortdescriptor sortdescriptorwithkey:hiredate Ascending:yes];
Two descriptor are placed in the array and passed to the array to be sorted.
If the object is NSString, that is, the string array sort, it is simpler, the Sortdescriptor key is directly specified as nil, directly sort the object, not one of the object's properties.
Nssortdescriptor *descriptor = [nssortdescriptor sortdescriptorwithkey:nil Ascending:yes];
Nsarray *descriptors = [Nsarray arraywithobject:descriptor];
Nsarray *mydataarray = [Nsarray arraywithobjects:@ "What", @ "Xero", @ "Highligth", @ "mountain", @ "Victory", @ "Balance", NIL];
Nsarray *resultarray = [Mydataarray sortedarrayusingdescriptors:descriptors];
NSLog (@ "%@", resultarray);
Nsarray uses sortedarrayusingdescriptors to return the sorted array.
Nsmutablearray can be used to sort the array itself directly using Sortusingdescriptors.
To sort a string array using Nssortdescriptor