使用NSPredicate来检测NOT CONTAINS

我放弃。 我试过每个组合,我可以想象检查一个string是否包含另一个string。 下面是一个描述我想要做什么的直观语法的例子:

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

不pipe我如何移动NOT,使用! 运算符,移动圆括号或完全删除它们,我总是得到一个exceptionparsing这个expression式。

这个expression有什么问题?

编辑:我打电话时发生exception

 [pMetadataQuery setPredicate:pPredicate]; 

而exception是: *因未捕获exception'NSInvalidArgumentException'而终止应用程序,原因:'给NSMetadataQuery(kMDItemFSName CONTAINS [c]“某些string”)的NSComparisonPredicate的未知types“

我完成了以下工作:

 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); 

testArray中的三个第二个对象在OS X v10.7和iOS v4.3下以filteredArray结尾。 所以这个问题不是谓词 – 在技术上使这个问题成为一个完整的答案 – 这是NSMetadataQuery某种限制。 可悲的是我没有这方面的经验,但是这肯定是研究的下一个问题。

Swift 3.0

 let predicate = NSPredicate(format: "NOT (%K CONTAINS[c] %@)", "someKey", "Some String") let testArray: [Any] = [[ "someKey" : "This sure is Some String" ], [ "someKey" : "I've nothing to say" ], [ "someOtherKey" : "I don't even have that key" ]] let filteredArray: [Any] = testArray.filter { predicate.evaluate(with: $0) } print("found \(filteredArray)")