Obj-C:使用字符串NSPredicate过滤数组?

问题描述

我遇到了最奇怪的问题。我正在使用下面的代码来过滤我的数组:

nspredicate *predicate = [nspredicate predicateWithFormat:@"scheduleddate contains [CD] %@",@"Wed,Feb 17"];
    
self.dailySchedule = [self.clients filteredArrayUsingPredicate:predicate];

它完美地工作。但是,我想用更改过滤数组的字符串,所以我将代码更改为:

NSDate *todayIs = [NSDate date];
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
dateFormatter2.dateFormat = @"EEEE,MMM d,yyyy ";
self.theDateIs = [dateFormatter2 stringFromDate: todayIs];
NSLog(@"%@",self.theDateIs);

nspredicate *predicate = [nspredicate predicateWithFormat:@"scheduleddate contains [CD] %@",self.theDateIs];

self.dailySchedule = [self.clients filteredArrayUsingPredicate:predicate];

出于某种原因,当我使用第二行代码时,即使填充了 self.myString(记录时,self.mystring 返回 Wed,2 月 17 日),它返回数组空,即使有结果字段预定日期包含 2 月 17 日,星期三。

奇怪的是,当我真正写出第一个示例中的字符串时,它可以正常工作。

知道为什么会这样吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)