NSSortDescriptor 无缘无故地从数组中删除项目

NSSortDescriptor Removing Items From Array For No Apparant Reason

我有两个数组,它们根据具有不同数量 NSNumber 对象的数组进行排序。 当我对其进行排序时,返回的名称数组已删除其中一项 - 为什么会这样?!代码:

NSDictionary *temp = [NSDictionary dictionaryWithObjects:self.names forKeys:self.times];
            NSSortDescriptor *theDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:NO selector:@selector(compare:)];
            self.times = [[temp allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:theDescriptor]];
            self.names = [temp objectsForKeys:self.finishedTimes notFoundMarker:[NSNull null]];

我运行以下:

NSDictionary *temp =
@{
    @"Name 2" : @"Time 2",
    @"Name 1" : @"Time 1",
    @"Name 3" : @"Time 3",
};

NSArray *times = [[temp allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSLog(@"Names: %@", [temp objectsForKeys:times notFoundMarker:[NSNull null]]);

输出符合预期:

2015-12-17 10:37:52.879 Test[6503:273457] Names: (
    "Time 1",
    "Time 2",
    "Time 3"
)

NSArray 在排序时不删除项目;你的问题出在你没有公开的一些代码中。