2 bluetooth99 bluetooth99 于 2012.12.25 16:48 提问

过滤NSMutableArray的结果

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;
    }
)

怎么实现根据state"FLorida"对NSMutableArray进行分组:

(
        {
        City = "Orlando";
       Name = "Shoreline Dental";
        State = Florida;
    },
 {
        City = "Orlando ";
        Name = "Roast Street";
        State = Florida;
    }
)

代码还是现实先前的四个dictionary。

NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Florida" ascending:YES];
       NSArray * descriptors = [NSArray arrayWithObject:valueDescriptor];
        NSArray * sortedArray = [arr sortedArrayUsingDescriptors:descriptors];

.

1个回答

zhanglei5415
zhanglei5415   Rxr 2012.12.26 13:32
已采纳

如果是排序的话,你可以用NSSortDescriptor.
但你想要的是,根据state="FLorida"来过滤,你可以尝试使用NSPredicate来过滤NSMutableArray 中的数据并返回结果。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!