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.
- 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)
|
- 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.