正しい方向へのポインタはありがたいことに受け取られます、
次の形式のNSDictionaryがあります。
{
3 = "special-collection-procedures-see-notes|";
13 = "<p>None Given</p>";
16 = "";
6 = "<p>Arrange for sample to be separated at an interim site and subsequently transport frozen to lab, if it cannot reach lab within one hour.</p>";
9 = "<p>Stored in laboratory at -20C</p>";
12 = "<p>None</p>";
2 = "images/tubes/lightblue_tube_large.png";
15 = "";
5 = "";
8 = "Up to 28 days";
11 = "<p>Some indications: Hereditary Angioedema</p><p>Sample type is citrated plasma though plain serum can also be used.</p>";
1 = " Functional C1 esterase inhibitor";
14 = "|";
4 = "5-10 mL";
7 = "<p>Frozen if unable to deliver within one hour</p>";
10 = "<p>expressed as a percentage of a control serum with 75% -125% being classed as normal.</p>";
}
順序が次のようになるようにキーを並べ替えたいと思います。
1 = " Functional C1 esterase inhibitor";
2 = "images/tubes/lightblue_tube_large.png";
等。
私はこのコードを持っています:
NSArray *myArray;
myArray = [[valuesDictionary allKeys] sortedArrayUsingComparator: ^(id obj1, id obj2) {
if ([obj1 integerValue] > [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedDescending;
}
if ([obj1 integerValue] < [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];
NSMutableDictionary *sortedDisplay = [[NSMutableDictionary alloc] init];
for (id object in myArray) {
// do something with object
[sortedDisplay setObject:[valuesDictionary objectForKey:object] forKey:object];
}
これにより、ソートされたmyArrayが得られます:1、2、3、4、5、6、7、8、9、10、11、12、13、14、15、16
しかし、最終的な「ソートされた」可変辞書はソートされていません。
sortedDisplayの説明の印刷:
{
13 = "<p>None Given</p>";
12 = "<p>None</p>";
11 = "<p>Some indications: Hereditary Angioedema</p><p>Sample type is citrated plasma though plain serum can also be used.</p>";
7 = "<p>Frozen if unable to deliver within one hour</p>";
6 = "<p>Arrange for sample to be separated at an interim site and subsequently transport frozen to lab, if it cannot reach lab within one hour.</p>";
2 = "images/tubes/lightblue_tube_large.png";
1 = " Functional C1 esterase inhibitor";
14 = "|";
15 = "";
10 = "<p>expressed as a percentage of a control serum with 75% -125% being classed as normal.</p>";
9 = "<p>Stored in laboratory at -20C</p>";
8 = "Up to 28 days";
5 = "";
4 = "5-10 mL";
3 = "special-collection-procedures-see-notes|";
16 = "";
}
私は何が間違っているのですか?