Objective-c has a sort of API that saves us a lot of things.
There are 3 main ways to do this.
Nsarray *unsortedarray = @[@5,@3,@8,@1,@7]; Nsarray *sortedarray = [Unsortedarray sortedarrayusingcomparator:^nscomparisonresult (ID obj1, id obj2) { return [ Obj1 compare:obj2];}];
Nsarray *unsortedarray = @[@5,@3,@8,@1,@7]; Nssortdescriptor *adesc = [[Nssortdescriptor alloc] initwithkey:@ "IntegerValue" ascending:yes]; Nsarray *sortedarray2 = [Unsortedarray Sortedarrayusingdescriptors:@[adesc]];
Notice the method one:
[Obj1 Compare:obj2]; Is the Compare method that NSNumber implements, can implement own compare method for the model that oneself defines.
-(Nscomparisonresult) Compare: (Person *) Otherperson {return [Self.dateofbirth Compare:otherPerson.dateOfBirth];}
As this code, is sorted by person's birthday.
The basics of iOS development