Created
April 10, 2012 19:57
-
-
Save setoh2000/2354043 to your computer and use it in GitHub Desktop.
NSMutableOrderedSetを使って2つの配列(array1, array2)を重複なしに合体させてソートされた配列(array3)を得る方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableOrderedSet *set = [NSMutableOrderedSet orderedSetWithArray:array1]; | |
[set addObjectsFromArray:array2]; | |
array3 = [set sortedArrayUsingComparator:^(NSString *obj1, NSString *obj2) { | |
return [obj1 compare:obj2]; | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
文字列が入っているのを前提にしてるのでComparatorの引数をNSStringにしていますがidでもOKです。というかソートしているからOrderedSetじゃなくても良いかも。。