Xcode 4 中的 NSPredicateEditor
Xcode 4 的谓词编辑器控件有点问题 - 我认为我做的一切都是正确的,而且看起来 IDE 本身确实被破坏了。
我在编写的应用程序中遇到了这个问题,但为了隔离它,我执行了以下操作:
创建一个带有窗口的新项目。在 XIB 编辑器中,向其中添加一个 NSPredicateEditor,并添加一行。将其保留为关键路径/字符串并添加两个关键路径 - “标题”和“作者”。使其不区分大小写和变音符号。
创建 NSWindowController 的子类并为谓词编辑器添加 IBOutlet。
在awakeFromNib中,放入以下代码:
NSPredicate *myPredicate = [NSPredicate predicateWithFormat: @"(title CONTAINS[CD] %@) AND (writer CONTAINS[CD] %@)", @"", @""];
[_predicateEditor setObjectValue:myPredicate];
这会在控制台中生成以下内容:
2011-04-12 15:59:37.709 PredicateTest[38419:903] 警告 - 无法找到与谓词标题匹配的模板 CONTAINS[cd] ""
2011 -04-12 15:59:37.710 PredicateTest[38419:903] 警告 - 无法找到模板匹配谓词编写器 CONTAINS[cd] ""
当我单击 (+) 按钮添加新行时,我得到以下内容:
2011-04-12 15:59:40.044 PredicateTest[38419:903] 无法使用 nil 运算符或表达式创建比较谓词。
我的想法是否正确,我在这里没有做错任何事情,这应该有效吗?如果我将谓词编辑器行模板从关键路径更改为远离关键路径,然后将其切换回关键路径,并编辑关键路径列表,则 Xcode 会因内部一致性异常而崩溃,这让我认为 Xcode 4 可能在以下情况下无法达到要求涉及谓词编辑。
有人有什么想法吗?我尝试过在代码中而不是 XIB 编辑器中创建 NSPredicateEditor,但无休止的混乱却无济于事。谓词编辑功能是阻碍我向商店发布应用程序的全部原因,所以这有点烦人。
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:
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.
Create a subclass of NSWindowController and add an IBOutlet for the predicate editor.
In awakeFromNib, put the following code:
NSPredicate *myPredicate = [NSPredicate predicateWithFormat: @"(title CONTAINS[CD] %@) AND (writer CONTAINS[CD] %@)", @"", @""];
[_predicateEditor setObjectValue:myPredicate];
This yields the following in the console:
2011-04-12 15:59:37.709 PredicateTest[38419:903] Warning - unable to find template matching predicate title CONTAINS[cd] ""
2011-04-12 15:59:37.710 PredicateTest[38419:903] Warning - unable to find template matching predicate writer 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] Cannot create a comparison predicate with nil operator or expression.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道这不是您想听到的答案,但我强烈建议以编程方式设置谓词编辑器。根据我的经验,在 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.
这似乎确实是 xCode 4 中的一个错误。当您记录由 predicateEditor 形成的谓词时,您会看到它听起来
而不是:
第一个样式出现在 xCode 4 中,后者出现在 xCode 3 中。
It seems to be a bug in xCode 4 indeed. When you log the predicate formed by the predicateEditor, you'll see that it sounds
instead of:
The first style occurs in xCode 4 and the latter in xCode 3.
我对 XCode 4 和 NSPredicateEditor 也有同样的问题,所以这不仅仅是你的问题。我能够在 XCode 3 中打开我的代码,删除 IB 中的绑定并重新分配绑定,并且它可以正常工作。这与 XCode 4 设置绑定的方式有关 - 它似乎有问题。如果 XCode 3 不是一个选项,那么以编程方式设置它可能是最好的答案。
I have the same issue with XCode 4 and NSPredicateEditor, so it's not just you. I was able to open my code in XCode 3, delete the bindings in IB and reassign the bindings and it worked normally. It has something to do with the way that XCode 4 is setting up the bindings – it appears to be buggy. Setting it programmatically is probably the best answer if XCode 3 is not an option.
使用 XCode4 遇到同样的问题,不幸的是我无法使用 Xcode3 的 IB 进行更多测试。
从此处找到的示例开始 http://nvie.com/posts/nspredicateeditor-tutorial/我怀疑 XCode4 IB 有错误,因为通过 IB 在谓词编辑器中添加键路径并在 DEFAULT_PREDICATE 中添加条目会导致“警告 - 无法找到模板匹配谓词”。
检查此示例以了解;)
似乎有已知问题?也许我错过了一些东西..
running into the same problem with XCode4, unfortunatly i can't test no more with Xcode3's IB.
Starting with the sample found here http://nvie.com/posts/nspredicateeditor-tutorial/ i suspect XCode4 IB to have bugs, because adding a keypath in Predicate Editor via IB and adding an entry in the DEFAULT_PREDICATE leads to "Warning - unable to find template matching predicate"..
Check this sample to understand ;)
Seems there's known issue ? Maybe i'm missing something..