为什么我的NSDictionary键按字母顺序排序

Jam*_*nay 4 iphone cocoa-touch objective-c

我正在使用我发现的教程中的NSDictionary,但我只是有一个简单的问题,为什么按字母顺序排序?

NSArray *array = [[NSArray alloc] initWithObjects:userName, nil];
    NSArray *array2 = [[NSArray alloc] initWithObjects:@"Other Data", @"Second Entry", nil];

    NSDictionary *temp =[[NSDictionary alloc] initWithObjectsAndKeys:array, @"Name", array2, @"A",nil];

    self.sortedKeys =[[temp allKeys] sortedArrayUsingSelector:@selector(compare:)];
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助.

bbu*_*bum 18

因为你按字母顺序排序?

self.sortedKeys =[[temp allKeys] sortedArrayUsingSelector:@selector(compare:)];
Run Code Online (Sandbox Code Playgroud)

请注意,字典的键本质上是无序的.如果您需要将某种排序顺序应用于键,则需要将其与字典分开进行维护.