Ios predicateWithSubstitutionVariables始终引发异常
我试图使用predicateWithSubstitutionVariables过滤对象数组,这段代码引发异常Ios predicateWithSubstitutionVariables始终引发异常,ios,nspredicate,Ios,Nspredicate,我试图使用predicateWithSubstitutionVariables过滤对象数组,这段代码引发异常 NSPredicate *pSample = [NSPredicate predicateWithFormat:@"name CONTAINS [c] $variable"]; [pSample predicateWithSubstitutionVariables:@{@"variable":@"sample string"}]; NSLog(@"%@", [mArray filtere
NSPredicate *pSample = [NSPredicate predicateWithFormat:@"name CONTAINS [c] $variable"];
[pSample predicateWithSubstitutionVariables:@{@"variable":@"sample string"}];
NSLog(@"%@", [mArray filteredArrayUsingPredicate:pSample]);
我得到的异常:
reason: 'Can't get value for 'variable' in bindings {
}.
为什么我不能用这个?(我不是在寻找替代解决方案)更改代码如下:
NSPredicate *pSample = [NSPredicate predicateWithFormat:@"name CONTAINS [c] $variable"];
NSPredicate *actualPredicate = [pSample predicateWithSubstitutionVariables:@{@"variable":@"sample string"}];
NSLog(@"%@", [mArray filteredArrayUsingPredicate: actualPredicate]);
您创建的第一个谓词是用于创建实际谓词的模板predicateWithSubstitutionVariables
提供所需的实际谓词