使用NSPredicate检测NOT CONTAINS

var*_*ian 5 cocoa-touch objective-c ios

我放弃.我已经尝试了我可以想象的每个组合来检查字符串是否包含另一个字符串.这是一个描述我想要做的直观语法的例子:

    NSPredicate* pPredicate = [NSPredicate predicateWithFormat:@"NOT (%K CONTAINS[c] %@)",
NSMetadataItemFSNameKey, 
[NSString stringWithFormat:@"Some String"]];
Run Code Online (Sandbox Code Playgroud)

无论我如何移动NOT,使用!相反,运算符移位括号或完全删除它们,我总是得到解析此表达式的异常.

这个表达有什么问题?

编辑:当我打电话时发生异常

[pMetadataQuery setPredicate:pPredicate];
Run Code Online (Sandbox Code Playgroud)

并且例外是:*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'给NSMetadataQuery提供了未知类型的NSComparisonPredicate(kMDItemFSName CONTAINS [c]"Some String")'

Tom*_*mmy 11

我取得了圆满成功:

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"NOT (%K CONTAINS[c] %@)",
        @"someKey",
        [NSString stringWithFormat:@"Some String"]];
NSArray *testArray =
    [NSArray arrayWithObjects:
        [NSDictionary dictionaryWithObject:@"This sure is Some String" forKey:@"someKey"],
        [NSDictionary dictionaryWithObject:@"I've nothing to say" forKey:@"someKey"],
        [NSDictionary dictionaryWithObject:@"I don't even have that key" forKey:@"someOtherKey"],
        nil];

NSArray *filteredArray = [testArray filteredArrayUsingPredicate:predicate];
NSLog(@"found %@", filteredArray);
Run Code Online (Sandbox Code Playgroud)

在OS X v10.7和iOS v4.3下,三个中的第二个两个对象testArray最终filteredArray进入.所以这个问题不是谓词 - 从技术上来说这是一个完整的答案 - 这是一种限制NSMetadataQuery.可悲的是,我没有那方面的经验,但它肯定是下一个研究的东西.