The basics of iOS development

Source: Internet
Author: User

Objective-c has a sort of API that saves us a lot of things.

There are 3 main ways to do this.

    • Nscomparator
Nsarray *unsortedarray = @[@5,@3,@8,@1,@7]; Nsarray *sortedarray = [Unsortedarray sortedarrayusingcomparator:^nscomparisonresult (ID obj1, id obj2) {    return [ Obj1 compare:obj2];}];
    • Nsdescriptor
Nsarray *unsortedarray = @[@5,@3,@8,@1,@7]; Nssortdescriptor *adesc = [[Nssortdescriptor alloc] initwithkey:@ "IntegerValue" ascending:yes]; Nsarray *sortedarray2 = [Unsortedarray Sortedarrayusingdescriptors:@[adesc]];
    • Custom Selector

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.