Two NSArray skills

Source: Internet
Author: User
Nijino. cnblog20140105nsarray-skills I previously talked about how to remove repetitive elements in NSArray in Netease's technology blog. I recently watched the WWDC2013 video and found that Apple engineers have a simpler method for Array deduplication. There is also a simple method for reverse sorting of arrays, so I can quickly record them for backup. NSArray Inverse

I talked about how to remove repetitive elements in NSArray in Netease's technology blog before http://nijino.cn/blog/2014/01/05/nsarray-skills. I recently watched the WWDC2013 video and found that Apple engineers have a simpler method for Array deduplication. There is also a simple method for reverse sorting of arrays, so I can quickly record them for backup. NSArray Inverse

From: http://nijino.cn/blog/2014/01/05/nsarray-skills/


Previously, I talked about how to remove repeated elements in NSArray in Netease's technical blog. I recently watched the WWDC2013 video and found that Apple engineers have a simpler method for Array deduplication. There is also a simple method for reverse sorting of arrays, so I can quickly record them for backup.

  1. NSArray Reverse Order
Reverse sequence of NSArray

123
NSArray *arr = @[@"first",@"second"];arr = arr.reverseObjectEnumerator.allObjects;NSLog(@"%@",arr);

Output result:

Reverse Result

1234
2014-01-05 13:52:09.303 CircleAudio[39584:70b] (second,first)

  1. NSArray fast deduplication
Make NSArray distinct

123
NSArray *arr = @[@"first",@"second",@"first"];arr = [arr valueForKeyPath:@"@distinctUnionOfObjects.self"];NSLog(@"%@",arr);

Output result:

Result

1234
2014-01-05 13:54:53.457 CircleAudio[39976:70b] (first,second)

The above techniques are all learned from WWDC2013 session 228. There are also some skills, such as associating two arrays and removing duplicates. Interested users can download their own video studies.

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.