Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSPredicate:使用filteredArrayUsingPredicate筛选NSDateComponents数组时发送到实例的无法识别的选择器_Ios_Nsarray_Nsdate_Nspredicate_Nsdatecomponent - Fatal编程技术网

Ios NSPredicate:使用filteredArrayUsingPredicate筛选NSDateComponents数组时发送到实例的无法识别的选择器

Ios NSPredicate:使用filteredArrayUsingPredicate筛选NSDateComponents数组时发送到实例的无法识别的选择器,ios,nsarray,nsdate,nspredicate,nsdatecomponent,Ios,Nsarray,Nsdate,Nspredicate,Nsdatecomponent,我有一些代码,其中包含从现在到一年的日期数组 NSCalendar* calendar = [NSCalendar currentCalendar]; NSMutableArray *dateComponentsInRange = [NSMutableArray new]; NSDate *curDate = [dates objectAtIndex:0]; while ([curDate timeIntervalSince197

我有一些代码,其中包含从现在到一年的日期数组

        NSCalendar* calendar = [NSCalendar currentCalendar];
        NSMutableArray *dateComponentsInRange = [NSMutableArray new];
        NSDate *curDate = [dates objectAtIndex:0];

        while ([curDate timeIntervalSince1970] <= [[dates lastObject] timeIntervalSince1970])
        {
            NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:curDate];
            [dateComponentsInRange addObject:components];
            curDate = [curDate dateWithNextDay];
        }
但是我得到了以下错误

 [__NSCFString evaluateWithObject:substitutionVariables:]: unrecognized selector sent to instance

将字符串添加到数组并将其用作谓词

尝试:


根据Apple Docs
orPredicateWithSubpredicates
的说法,它需要一个
NSPredicate
数组,但您传递的是一个
NSString
对象数组

错误是

[\uu NSCFString evaluateWithObject:substitutionVariables::]:发送到实例的选择器无法识别

这是正确的,因为
evaluateWithObject:substitutionVariables
不是为
NSString
定义的,而是为
NSPredicate


Src:Apple Documentation

确保没有零日期。您错过了错误消息的重要部分。剩下的怎么说?数组中没有nil日期,我甚至用数组中的一个非nil元素尝试过,但仍然得到了错误,这就是我得到的所有消息
 [__NSCFString evaluateWithObject:substitutionVariables:]: unrecognized selector sent to instance
    NSDateComponents *components = nil;
    NSMutableArray *predicates = [NSMutableArray array];;
    for (NSDate *currentdate in dates)
    {
        components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:currentdate];
        NSString *preficateFormat = [NSString stringWithFormat:@"(SELF.day  != %d AND SELF.month != %d AND SELF.year != %d)",[components day],[components month], [components year]];
        NSPredicate * predicate = [NSPredicate predicateWithFormat:preficateFormat];
        [predicates addObject:predicate];
    }
    NSPredicate *predicate = [NSCompoundPredicate orPredicateWithSubpredicates:predicates];
    NSArray *filteredArr = [dateComponentsInRange filteredArrayUsingPredicate:predicate];