[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
ゲーム、アニメ、CG、iOS開発など思いついたことを記事にしています。 管理人が3人いますので、記事にまとまりはないと思います。 iPhoneアプリのレビュー依頼も受け付けています。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
NSMutableArray *sortArray = [NSMutableArray array]; for(int i=0; i<10; i++){ NSString *name = [NSString stringWithFormat:@"Name%d", i]; NSDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys: name, @"key1", @"type", @"key2", nil]; [sortArray addObject:dic] } NSSortDescriptor *sortDescName; NSSortDescriptor *sortDescType; NSMutableArray *sortDescArray; sortDescName = [[NSSortDescriptor alloc] initWithKey:@"key1" ascending:YES selector:@selector(localizedStandardCompare:)]; sortDescType = [[NSSortDescriptor alloc] initWithKey:@"key2" ascending:YES]; sortDescArray = [NSMutableArray arrayWithObjects: sortDescName, sortDescType, nil]; [sortArray sortedArrayUsingDescriptors:sortDescArray];
***結果***
Name0 type
Name1 type
Name2 type
・・・
Name9 type
上記例ではname,typeの順で昇順ソートされます。
localizedStandardCompareを使えば、簡単に実現できます。