NSPredicateEditor在Xcode 4 [英] NSPredicateEditor in Xcode 4

查看:133
本文介绍了NSPredicateEditor在Xcode 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 4的谓词编辑器控件的一个问题 - 我认为我做的一切正确,它真的似乎IDE本身是破坏了。

Bit of an issue with Xcode 4's predicate editor controls - I think I'm doing everything right, and it really seems like the IDE itself is busted.

我在我写的应用程序中有这个问题,但是为了隔离它,我做了以下操作:

I'm having this issue in an app I'm writing, but to isolate it, I did the following:

使用窗口创建一个新项目。在XIB编辑器中,向其中添加NSPredicateEditor,并添加一行。将其保留为关键路径/字符串,并添加两个关键路径 - 标题和writer。

Create a new project with a window. In the XIB editor, add an NSPredicateEditor to it, and add one line. Leave it as key paths/strings and add two key paths - "title" and "writer". Make it case and diacritical insensitive.

创建NSWindowController的子类,并为谓词编辑器添加一个IBOutlet。

Create a subclass of NSWindowController and add an IBOutlet for the predicate editor.

在awakeFromNib中,输入以下代码:

In awakeFromNib, put the following code:


NSPredicate * myPredicate = [NSPredicate predicateWithFormat:@(title CONTAINS [CD]%@ AND(writer CONTAINS [CD]%@),@,@];

NSPredicate *myPredicate = [NSPredicate predicateWithFormat: @"(title CONTAINS[CD] %@) AND (writer CONTAINS[CD] %@)", @"", @""];

[_ predicateEditor setObjectValue:myPredicate];

[_predicateEditor setObjectValue:myPredicate];

这会在控制台中生成以下内容:

This yields the following in the console:

2011-04-12 15:59 :37.709 PredicateTest [38419:903]警告 - 无法找到模板匹配谓词标题CONTAINS [cd]

2011- 15:59:37.710 PredicateTest [38419:903]警告 - 无法找到模板匹配谓词编写器CONTAINS [cd]

+)按钮添加一个新行,我得到以下结果:

When I click the (+) button to add a new row, I get the following:

2011-04-12 15:59:40.044 PredicateTest [38419:903]具有nil运算符或表达式的比较谓词。

我认为我在这里没有做错事,这应该工作吗?如果我将谓词编辑器行模板更改为关键路径,然后将其切换回键路径,并编辑键路径列表,Xcode崩溃与内部一致性异常,这让我想,也许Xcode 4没有达到鼻烟它来到谓词编辑。

Am I right in thinking I'm not doing anything wrong here, and this should work? If I change the predicate editor row template away from key paths, then switch it back to key paths, and edit the list of key paths, Xcode crashes with an internal consistency exception, which makes me think maybe Xcode 4 is not up to snuff when it comes to predicate editing.

任何人有任何想法?我试着在代码而不是XIB编辑器中创建一个NSPredicateEditor,无尽的乱七八糟的无法使用。

Anyone got any ideas? I've tried creating an NSPredicateEditor in code rather than the XIB editor, and endless messing around to no avail. The predicate editing functionality is all that's holding me up releasing an app to the store, so this is kind of an annoyance.

推荐答案

这是一个令人厌烦的东西。我知道这不是你想听到的答案,但我高度建议以编程方式设置谓词编辑器。根据我的经验,在IB中设置它不是很直观。至少在代码中你可以明确地看到发生了什么。

I know this isn't the answer you want to hear, but I highly recommend setting up the the predicate editor programmatically. Setting it up in IB, in my experience, isn't very intuitive. At least in code you can explicitly see what's going on.

NSArray *keyPaths = @[[NSExpression expressionForKeyPath:@"title"],
                      [NSExpression expressionForKeyPath:@"writer"]];
NSArray *operators = @[@(NSEqualToPredicateOperatorType),
                       @(NSNotEqualToPredicateOperatorType),
                       @(NSBeginsWithPredicateOperatorType),
                       @(NSEndsWithPredicateOperatorType),
                       @(NSContainsPredicateOperatorType)];

NSPredicateEditorRowTemplate *template = [[NSPredicateEditorRowTemplate alloc] initWithLeftExpressions:keyPaths
                                                                          rightExpressionAttributeType:NSStringAttributeType
                                                                                              modifier:NSDirectPredicateModifier 
                                                                                             operators:operators 
                                                                                               options:(NSCaseInsensitivePredicateOption | NSDiacriticInsensitivePredicateOption)];

NSArray *compoundTypes = @[@(NSNotPredicateType),
                           @(NSAndPredicateType),
                           @(NSOrPredicateType)];
NSPredicateEditorRowTemplate *compound = [[NSPredicateEditorRowTemplate alloc] initWithCompoundTypes:compoundTypes];

[myPredicateEditor setRowTemplates:@[template, compound]];

这篇关于NSPredicateEditor在Xcode 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆