我有一个像这样的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中执行此搜索。请帮帮我。
由于
答案 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);