如何在NSMutableArray上搜索一些东西

时间:2014-08-03 07:42:22

标签: search nsmutablearray ios7.1

我有一个像这样的NSMutable数组

`

mutablearray
{
 "colour_id" = 1,
  "day_id" =  "2011-01-01 00:00:00 +0000"
},

{
 "colour_id" = 2,
  "day_id" =  "2011-05-06 00:00:00 +0000"
},

`

我想在2011-05-06 00:00:00 +0000中搜索NSMutableArray此特定日期是否可用。如何在ios中执行此搜索。请帮帮我。

由于

1 个答案:

答案 0 :(得分:0)

正确的做法是将每个day_id值转换为NSDate对象并调用[NSDate compare]以查看它是否相等,但是您可以作弊并简单地比较字符串,如果您确定它们将始终以这种格式出现:

NSArray *yourArray = ...;
NSString *colourId = nil;
for (NSDictionary *dict in yourArray) {
    if ([dict[@"day_id"] isEqualToString:@"2011-05-06 00:00:00 +0000"]) {
        colourId = dict[@"colour_id"];
        break;
    }
}
NSLog(@"Colour is %@", colourId);