macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

keysSortedByValueUsingSelector:

辞書の値でソートされたキーの配列を返します
-(NSArray *)keysSortedByValueUsingSelector:(SEL)comparator

解説

辞書の値でソートされたキーの配列を返します。

返り値

( NSArray * )

ソートされたキーの配列

引数

( SEL )comparator

比較する式

クラス

NSDictionary

Instance Methods

使用可能

10.0

参照

- allKeys
- sortedArrayUsingSelector:(NSArray)

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSArray *ar;
NSDictionary *dic = 
[NSDictionary dictionaryWithObjectsAndKeys:
@"4",@"d",
@"6",@"f",
@"1",@"b",
@"8",@"h",
@"5",@"e",
@"9",@"i",
@"1",@"a",
@"7",@"g",
@"3",@"c",
nil];

ar = [dic keysSortedByValueUsingSelector:@selector(compare:)];

NSLog([ar description]);
}

- (NSComparisonResult)compare:(Comp *)data
{
    return [[myOutlet string] compare:(NSString *)data];
}
@end