#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
Sort in array
Nsarray *[email protected][@ "MON", @ "TUE", @ "WED", @ "THU", @ "FRI", @ "SAT", @ "SUN"];
Nsarray *sarr=[week sortedarrayusingselector: @selector (compare:)];
for (id str in sarr) {
NSLog (@ "%@", str);
}
/*id when you are unsure about the type of an array element, you can select the ID
NSOBJCT and ID are all points to any object
NSObject must be strong when used
Instantcetype can only return objects of the same type as the method's class
Returns a value type, but absolutely cannot pass a parameter
ID can only return the position type of the alignment parameter suitable for
*/
Array sort--block
Nscomparator sort=^ (ID obj1,id obj2) {
return [Obj1 Compare:obj2];
};
Nsarray *arr=[week Sortedarrayusingcomparator:sort];
for (id str in arr) {
NSLog (@ "%@", str);
}
}
return 0;
}
Array sorting block sorting and sorting in arrays