Configuring NSPredicateEditor(RowTemplate) for Spotlight metadata queriesI'

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 04:38:06

I've found that working with NSPredicateEditor and friends in Interface Builder is an exceedingly tedious task. For that reason, I do all of my row template configuration in code.

For your situation, it doesn't sound like you need a custom row template subclass, so you could probably just do:

#define NSPERT NSPredicateEditorRowTemplate
NSPERT * template = [[NSPERT alloc] initWithLeftExpressions:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:kMDItemTextContent]] 
                               rightExpressionAttributeType:NSStringAttributeType
                                                   modifier:NSDirectPredicateModifier
                                                  operators:[NSArray arrayWithObject:
                                                             [NSNumber numberWithUnsignedInteger:NSContainsPredicateOperatorType]]
                                                    options:(NSCaseInsensitivePredicateOption|NSDiacriticInsensitivePredicateOption)];

Once you've got the template, simply add it to the predicateEditor:

NSMutableArray * templates = [[myPredicateEditor rowTemplates] mutableCopy];
[templates addObject:template];
[template release];
[myPredicateEditor setRowTemplates:templates];
[templates release];

As for translating the "kMDItemTextContent", if it doesn't happen automatically (and I think it might), you could use the NSPredicateEditor localization options to display a different name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!