我有一个这样的 NSMutableArray:
(
{
City = "Orlando";
Name = "Shoreline Dental";
State = Florida;
},
{
City = "Alabaster ";
Name = Oxford Multispeciality;
State = Alabama;
},
{
City = Dallas;
Name = "Williams Spa";
State = Texas;
},
{
City = "Orlando ";
Name = "Roast Street";
State = Florida;
}
)
现在我如何对这个 NSMutableArray 进行排序以获得与我期望得到的州“佛罗里达”相对应的结果
(
{
City = "Orlando";
Name = "Shoreline Dental";
State = Florida;
},
{
City = "Orlando ";
Name = "Roast Street";
State = Florida;
}
)
我去找了这段代码,但它再次显示了之前的四个字典。
NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Florida" ascending:YES];
NSArray * descriptors = [NSArray arrayWithObject:valueDescriptor];
NSArray * sortedArray = [arr sortedArrayUsingDescriptors:descriptors];